小页面的行号

小页面的行号

我无法在方框左侧添加行号。有人能帮我吗?

\documentclass{article}

\begin{document}

\fbox{\fbox{

\begin{minipage}{0.8\linewidth}

\textbf{def} mapper (key, value):

\hspace{7mm}\textbf{for} word \textbf{in} value.split():

\hspace{14mm}\textbf{yield} word, 1\\

\textbf{def} reducer (key , values):

\hspace{7mm}\textbf{yield} key, sum(values)\\


\textbf{if} name == "main":

\hspace{7mm}\textbf{import} dumbo

\hspace{7mm}dumbo.run (mapper, reducer, combiner=reducer )

\end{minipage}

}}

\end{document}

谢谢

答案1

\documentclass{article}
\usepackage{listings}

\lstset{numbers=left,numberstyle=\tiny,numbersep=1em,
  morekeywords={def,for,yield,if,import},
  keywordstyle=\bfseries,frame=TLBR}
\begin{document}


\begin{lstlisting}
def mapper (key, value):
  for word in value.split():
    yield word, 1
def reducer (key , values):
  yield key, sum(values)
  if name == "main":
    import dumbo
    dumbo.run (mapper, reducer, combiner=reducer )
\end{lstlisting}

\end{document}

相关内容