Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have the following in my LateX code:

\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}

Now, the result I get overlaps/overwrites positions for the numberings: Very Messy Result

This obviously, not what anyone would want to do. How can I fix the numbering?

Thanks for all the help?

share|improve this question
    
Depending on your application, I would consider using \lstinline instead... Might I ask what you're trying to get at? (Just out of curiosity.) –  Sean Allred Feb 1 at 5:59
    
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Mar 20 at 22:52

1 Answer 1

up vote 4 down vote accepted

Leave a blank line (or use \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}

enter image description here

Or use \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}

enter image description here

share|improve this answer
    
Is there a TeX command line where I could use a help interface? For example, could I do help(par)? –  CodeKingPlusPlus Feb 1 at 1:49
    
@codeking You can use the command texdoc but that is mostly for packages. –  Kartik Feb 1 at 2:12
    
@CodeKingPlusPlus there's \show that gives the "definition" of commands, but since \par is a TeX primitive, it won't help here. \par end the paragraph; it is equivalent to leaving a blank line in the code. –  Gonzalo Medina Feb 1 at 2:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.