发布时间:2019-08-26 07:55:33编辑:auto阅读(2047)
翻译 https://stackoverflow.com/questions/3175105/writing-code-in-latex-document 内的内容。
其实就是使用Listings包,一个例子如下:
在正文前(\begin{document}
之前)使用如下代码设置参数:
\usepackage{listings}
\usepackage{color}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{frame=tb,
language=Python,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=none,
numberstyle=\tiny\color{gray},
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
breaklines=true,
breakatwhitespace=true,
tabsize=3
}
在正文里面的时候在lstlisting
环境内放置代码即可,例子如下:
\begin{lstlisting}
import numpy as np
if __name__ == '__main__':
print(np.arange(10))
\end{lstlisting}
结果如下:
上一篇: python redis 断开连接
下一篇: python画图常用颜色
48610
47600
38394
35615
30067
26787
25793
20683
20424
18825
106°
189°
223°
245°
240°
249°
285°
327°
457°
441°