如果我lineskip
在 中指定了lstlisting
,它也会影响标题。我该如何防止这种情况发生?
例子:
\documentclass[a5paper]{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[float,
basicstyle=\ttfamily\footnotesize,
lineskip=-0.7ex,
columns=fixed,basewidth=0.5em,
captionpos=b,
caption={Long caption text that spans at least two lines to show the lineskip.}
]
one
two
three
\end{lstlisting}
\begin{lstlisting}[float,
basicstyle=\ttfamily\footnotesize,
%lineskip=-0.7ex,
columns=fixed,basewidth=0.5em,
captionpos=b,
caption={Long caption text that spans at least two lines to show the lineskip.}
]
one
two
three
\end{lstlisting}
\end{document}
答案1
您可以使用caption
包setspace
。
\documentclass[a5paper]{article}
\usepackage{listings}
\usepackage{caption}
\usepackage{setspace}
\captionsetup[lstlisting]{font={stretch=1}}
\begin{document}
\begin{lstlisting}[float,
basicstyle=\ttfamily\footnotesize,
lineskip=-0.7ex,
columns=fixed,basewidth=0.5em,
captionpos=b,
caption={Long caption text that spans at least two lines to show the lineskip.}
]
one
two
three
\end{lstlisting}
\begin{lstlisting}[float,
basicstyle=\ttfamily\footnotesize,
%lineskip=-0.7ex,
columns=fixed,basewidth=0.5em,
captionpos=b,
caption={Long caption text that spans at least two lines to show the lineskip.}
]
one
two
three
\end{lstlisting}
\end{document}
答案2
\lst@MakeCaption
要做的补丁\linespread{1}
:
\documentclass[a5paper]{article}
\usepackage{listings}
\usepackage{etoolbox}
\makeatletter
\patchcmd\lst@MakeCaption
{\ignorespaces}
{\linespread{1}\selectfont\ignorespaces}
{}{}
\makeatother
\begin{document}
\begin{lstlisting}[
float,
basicstyle=\ttfamily\footnotesize,
lineskip=-0.7ex,
columns=fixed,
basewidth=0.5em,
captionpos=b,
caption={Long caption text that spans at least two lines to show the lineskip.}
]
one
two
three
\end{lstlisting}
\begin{lstlisting}[
float,
basicstyle=\ttfamily\footnotesize,
columns=fixed,basewidth=0.5em,
captionpos=b,
caption={Long caption text that spans at least two lines to show the lineskip.}
]
one
two
three
\end{lstlisting}
\end{document}