查看示例代码和屏幕截图:
\documentclass[UTF8]{article}
\usepackage{listings}
\usepackage{color}
\begin{document}
\lstset{
basicstyle=\ttfamily\footnotesize,
language=Python,
breaklines=true,
frame=single,
breakatwhitespace=false,
numbers=left
}
%\lstinputlisting{code/test.py}
\begin{lstlisting}
class MyClass:
def __init__(self):
#revolve_map: Rotation invariant mode 36 characteristic values. Get a dictionary from small to large numbers.
self.revolve_map={0:0,1:1,3:2,5:3,7:4,9:5,11:6,13:7,15:8,17:9,19:10,21:11,23:12,
25:13,27:14,29:15,31:16,37:17,39:18,43:19,45:20,47:21,51:22,53:23,55:24,
59:25,61:26,63:27,85:28,87:29,91:30,95:31,111:32,119:33,127:34,255:35}
#uniform_map: Equivalent model 58 characteristic values. Get a dictionary from small to large numbers.
self.uniform_map={0:0,1:1,2:2,3:3,4:4,6:5,7:6,8:7,12:8,
14:9,15:10,16:11,24:12,28:13,30:14,31:15,32:16,
48:17,56:18,60:19,62:20,63:21,64:22,96:23,112:24,
120:25,124:26,126:27,127:28,128:29,129:30,131:31,135:32,
143:33,159:34,191:35,192:36,193:37,195:38,199:39,207:40,
223:41,224:42,225:43,227:44,231:45,239:46,240:47,241:48,
243:49,247:50,248:51,249:52,251:53,252:54,253:55,254:56,
255:57}
\end{lstlisting}
\end{document}
在构建时,我看到许多警告,例如Overfull \hbox (42.20813pt too wide) in paragraph at lines 20--21
结果屏幕截图如下所示。
我已经使用了该breaklines=true
选项,但我不知道如何正确包装长源代码。