latex中添加C++代碼

用到listings宏包,模板以下:ios

\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}
相關文章
相關標籤/搜索