发布时间:2019-08-26 07:55:33编辑:auto阅读(2075)
翻译 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画图常用颜色
48798
47838
38609
35798
30220
26970
26005
20840
20622
19001
409°
489°
519°
525°
514°
495°
562°
625°
745°
782°