%引入包 \usepackage{listings} %全局设置 \lstset{ %编程语言 language=c++, xrightmargin=0pt, basicstyle=\small\sffamily, numbers=left, numberstyle=\tiny, frame=single, columns=fullflexible, showstringspaces=false, commentstyle=\color{red}, breaklines=true, framerule=0.7pt, frameround=tttt, rulecolor=\color{blue} }
直接插入代码
\begin{lstlisting}[firstline=2, lastline=5] for i:=maxint to 0 do begin { do nothing } end; Write(’Case insensitive ’); WritE(’Pascal keywords.’); \end{lstlisting}
引入一个文件
\lstinputlisting[lastline=4]{listings.sty}