After some \begin{lstlisting} ... \end{lstlisting}, LaTeX adds some additional vertical space. How can I avoid that?


  • please provide a MWE, which produces the given output
    – Micha
    Jun 11 '13 at 20:40
  • 1
    The answers here or here might help out.
    – Scott H.
    Jun 11 '13 at 20:43

Thanks to Scott H for the reference. It didn't directly helped me but it pointed out that the problem was my redefinition of \parskip and \baselineskip.

I'm using this now and it mostly works:

\begin{lstlisting}[belowskip=-0.8 \baselineskip]
  • 1
    You should never redefine \baselineskip directly in latex (use \linespread or a font size command) and \parskip can only be changed with some care. Jun 11 '13 at 21:17
  • 3
    Actually, the space above/below any listing is given by \medskipamount. See the listings documentation (section 2.7 Layout elements, p 15, under the heading Vertical space).
    – Werner
    Jul 11 '13 at 21:21
  • The extra space is also present when you increase linespacing with the \onehalfspacing command from the setspace package (needed in my case because of a specific body font with large ascenders and descenders, and a long line length). May 15 '17 at 11:21
  • How to use this at the same time with [language=SomeLang] ?
    – Asqiir
    Oct 27 '18 at 7:21
  • There is still space occurs after the lstlisting @Albert
    – alper
    Dec 5 '19 at 8:52

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.