コードリスト環境での行間隔を変更する

コードリスト環境での行間隔を変更する

コード環境で行間隔を狭くすることができません。強制的に設定する方法は?basicstyle=\linespread{0.8}何も変わりません。

\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

\selectfont行間隔の変更を「有効にする」コマンドを追加する必要があります。

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

ここに画像の説明を入力してください

リストの下の余分なスペースが気に入らない場合は、 を設定することもできますbelowskip=0pt

関連情報