11

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

shot

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

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}
  • 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. – David Carlisle 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). – Peter Flynn May 15 '17 at 11:21
  • How to use this at the same time with [language=SomeLang] ? – Asqiir Oct 27 '18 at 7:21

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.