2

I can't get a small line spacing for the code environment. How to force it? basicstyle=\linespread{0.8} doesn't change anything.

\documentclass[12pt, a4paper]{report}
\usepackage{listings}
\linespread{1.5}

\DeclareFixedFont{\ttm}{T1}{txtt}{m}{n}{10pt}

\lstset{
  basicstyle=\ttm\linespread{0.8},
}

\begin{document}
The line spacing is perfect here.

The line spacing is perfect here too.

\begin{lstlisting}
The code has 
too high 
line spacing
\end{lstlisting}

The line spacing is perfect here.

The line spacing is perfect here too.

\end{document}

1 Answer 1

5

You need to add the command \selectfont to "activate" the line spacing changes:

\lstset{
  basicstyle=\ttm\linespread{0.8}\selectfont
}

enter image description here

If you dislike the extra spacing below the listing, you can also set belowskip=0pt.

1
  • This is correct. I've been wandering around many posts suggesting the use of \linespread but none of those mentioned \selectfont. Thanks. Jun 17, 2022 at 20:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .