我的 LateX 代码中有以下内容:
\begin{enumerate}
\item
\begin{lstlisting}
x = [x for x in xrange(4, 9)]
\end{lstlisting}
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
现在,我得到的结果与编号的位置重叠/覆盖:
这显然不是任何人想要做的。我该如何修复编号?
谢谢你的帮助?
答案1
留一个空行(或者使用\par
):
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{enumerate}
\item
\begin{lstlisting}
x = [x for x in xrange(4, 9)]
\end{lstlisting}
\par
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
\par
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
\par
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
\par
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
\par
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
\par
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
\par
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
\par
\item
\begin{lstlisting}
x = [x for x in xrange(6)]
\end{lstlisting}
\end{enumerate}
\end{document}
或者使用\lstinline
:
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{enumerate}
\item
\lstinline{x = [x for x in xrange(4, 9)]}
\item
\lstinline{x = [x for x in xrange(6)]}
\item
\lstinline{x = [x for x in xrange(6)]}
\end{enumerate}
\end{document}