5

i want several code listings to be embedded in an item of a custom list environment. To achieve this i employ the lstlisting environment of the listings package. Unfortunately extra vertical space is appended to the lstlisting environment inside a list environment (see image below). Not a large skip but by all means annoying. This extra space vanishes if the same listing is placed outside the list environment. I can't figure out the reason for this extra space. Probably my current knowledge don't suffice to get rid of this space.

Maybe one of you experts can figure out the reason and can give me a hint how to remove the vertical extra space!? Maybe even a short explanation of this at least for the laymen strange behavior.

Thanks a lot for your effort...


Here is a minimal example which illustrates the problem:

 \documentclass[10pt]{article}
 \usepackage{listings}

 \lstset{frame=lines, aboveskip=0pt, belowskip=0pt}
 \begin{document}
 \begin{list}{}{}
     \item asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd 
     \begin{lstlisting}
 asdasd
     \end{lstlisting}%
 asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd
 \end{list}
 asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd
 \begin{lstlisting}
 asdasd
 \end{lstlisting}%
 asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd
 \end{document}

The crucial snippet of the compiled document is shown below:

vertical extra space after listings env in list env

5

The behaviour you're seeing is coming from the \parsep of the list environment.

From source2e you'll see that the vertical spacing of a list environment has the following parameters that can be tweaked

enter image description here

The particularly relevant parameter for your example is \parsep, so if you use

\begin{list}{}{\setlength{\parsep}{0pt}}

then you get

enter image description here

which I think is what you want :)

  • disclaimer: I know you said you wanted an expert- I don't consider myself an expert; I know just about enough to be somewhat-useful some of the time. hopefully this is one of those times :) – cmhughes Jul 21 '12 at 17:05
  • Thank you very much for your thorough explanation and the solution. Setting \parsep to 0pt solved it, like you've written. Seen from my current level your answer has definitely the expertise i was looking for. And i share your feeling, that you was useful at this instant of time as you posted this answer :) I hope that my comforting words help you to get out of your depression =) ... just kidding – user1146332 Jul 21 '12 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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