在特定情况下,我必须使用lstlisting
而不是Verbatim
,因为数学转义无法与后者正常工作。我设法让两者看起来一样,但lstlisting
忽略了我的baselinestretch
设置,因此行距太大:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{fancyvrb}
\usepackage{listings}
\usepackage[scaled=.73]{beramono}
\fvset{baselinestretch=0.94}
\lstdefinelanguage{scala}{
morekeywords={type}%
}
\lstset{
language=scala,%
% baselinestretch=0.94,% keyword doesn't exist
basicstyle=\ttfamily,%
fancyvrb=true,%
mathescape=true,%
}
\begin{document}
\begin{lstlisting}
type Vertex = ($\mathit{lb}_\mathsf{pre}$: Label, $\mathit{lb}_\mathsf{post}$: Label)
Next Line
Next Line
\end{lstlisting}
\begin{Verbatim}
type Vertex = ($\mathit{lb}_\mathsf{pre}$: Label, $\mathit{lb}_\mathsf{post}$: Label)
Next Line
Next Line
\end{Verbatim}
\end{document}
您可以在此处看到不同的行距:
差异不是很大,但对长列表的影响很大。将基线拉伸应用于 的最佳方法是什么lstlisting
?
答案1
使用basicstyle=\linespread{0.94}\ttfamily
如下例所示,各行间距完全相同
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{fancyvrb}
\usepackage{listings}
\usepackage[scaled=.73]{beramono}
\fvset{baselinestretch=.94}
\lstdefinelanguage{scala}{
morekeywords={type}
}
\lstset{
language=scala,
basicstyle=\linespread{.94}\ttfamily,
fancyvrb=true,
mathescape=true,
}
\begin{document}
\begin{lstlisting}
type Vertex = ($\mathit{lb}_\mathsf{pre}$: Label, $\mathit{lb}_\mathsf{post}$: Label)
Next Line
Next Line
\end{lstlisting}
\kern-50pt % back up to see that the lines are equally spaced
\begin{Verbatim}
type Vertex = ($\mathit{lb}_\mathsf{pre}$: Label, $\mathit{lb}_\mathsf{post}$: Label)
Next Line
Next Line
\end{Verbatim}
\end{document}