# avoid empty vert space after lstlisting

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 Jun 11 '13 at 20:40
• The answers here or here might help out. 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]
CyclotomicField(order).gen().coordinates_in_terms_of_powers()
\end{lstlisting}

• 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
• 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). 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] ? Oct 27 '18 at 7:21
• There is still space occurs after the lstlisting @Albert Dec 5 '19 at 8:52