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

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

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 :)

share|improve this answer
    
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
add comment

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.