枚举标签中的编号混乱/覆盖

枚举标签中的编号混乱/覆盖

我的 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}

在此处输入图片描述

相关内容