코드 목록 환경에서 줄 간격 변경

코드 목록 환경에서 줄 간격 변경

코드 환경에 맞게 작은 줄 간격을 얻을 수 없습니다. 강제하는 방법은 무엇입니까? 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.

관련 정보