用到listings宏包,模板如下:

\documentclass[UTF8]{ctexart}
\usepackage[a4paper,top=2cm,bottom=2cm,left=2cm,right=2cm]{geometry}
\usepackage{listings}
\lstset{
    numbers=left,   //添加代码的编号,在左侧
    basicsytle=\ttfamily,   //字母使用打字机字族
    language=C++  //高亮C++代码
}
\begin{document}
\section{第一题答案}
\begin{lstlisting}
#include<iostream>
using namespace std;
int main(){
    cout<<"hello world!"<<endl;
}
\end{lstlisting}
\end{document}

 

相关文章:

  • 2021-10-08
  • 2021-09-17
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2021-09-09
  • 2021-09-19
  • 2021-10-12
猜你喜欢
  • 2022-01-18
  • 2022-12-23
  • 2021-06-12
  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
  • 2021-10-26
相关资源
相似解决方案