题
目前,我正在写一个项目的报告,并解释稍有疯狂的联合国-直观的代码,我已经用我要把很多很多的简短摘录的例码。
我如何可以得到代码转乳胶是:
- 看起来不错
- 不会去的如果该行太长(表lstlisting或逐字)
- 是最好与其他文本
编辑(以为我想补充的设置,以便人们不必尝试和他们自己(而采取从维基教科书(链接进一步下降)和编辑为美好的事物))
好的设置:
\usepackage{color}
\usepackage{listings}
\lstset{ %
language=C++, % choose the language of the code
basicstyle=\footnotesize, % the size of the fonts that are used for the code
numbers=left, % where to put the line-numbers
numberstyle=\footnotesize, % the size of the fonts that are used for the line-numbers
stepnumber=1, % the step between two line-numbers. If it is 1 each line will be numbered
numbersep=5pt, % how far the line-numbers are from the code
backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
showspaces=false, % show spaces adding particular underscores
showstringspaces=false, % underline spaces within strings
showtabs=false, % show tabs within strings adding particular underscores
frame=single, % adds a frame around the code
tabsize=2, % sets default tabsize to 2 spaces
captionpos=b, % sets the caption-position to bottom
breaklines=true, % sets automatic line breaking
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
escapeinside={\%*}{*)} % if you want to add a comment within your code
}
\begin{lstlisting}
!!code!!
\end{lstlisting}
一个例子,这些设置:
解决方案
的 列表 包装很漂亮,非常灵活的(例如大小不同的意见和代码)。
其他提示
事实证明, lstlisting
是够格式码很好,但需要很大的调整。
维基教科书 有一个很好的例子的参数可以调整。
为简单的文件,我有时使用逐字,但是,清单是大块代码。
不隶属于 StackOverflow