我如何将逐字延伸设置为不同于“全局”设置?

我如何将逐字延伸设置为不同于“全局”设置?

在我的文件中,我需要使用 1.5 行拉伸。但是,verbatim我需要它是 1.0。我应该在序言中添加什么来实现这一点?

\documentclass{article}
\usepackage[nodisplayskipstretch]{setspace} \setstretch{1.5}
\begin{document} 
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Proin nibh augue, suscipit a, scelerisque sed, lacinia in, mi. Cras vel lorem. Etiam pellentesque aliquet tellus. Phasellus pharetra nulla ac diam.
\begin{verbatim}
A = 5
B = 123
C = 123123
\end{verbatim}
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Proin nibh augue, suscipit a, scelerisque sed, lacinia in, mi. Cras vel lorem. Etiam pellentesque aliquet tellus. Phasellus pharetra nulla ac diam.
\end{document} 

答案1

我建议另一项改进:

\documentclass{article}
\usepackage[nodisplayskipstretch]{setspace} \setstretch{1.5}

\usepackage{etoolbox}
\preto{\verbatim}{\edef\tempstretch{\baselinestretch}\par\setstretch{1}}
\appto{\endverbatim}{\vspace{-\tempstretch\baselineskip}\vspace{\baselineskip}}

第一个\preto几乎与 David 的技巧相同,但它还保存了\baselinestretch我们在环境末尾使用的值,以使verbatim环境周围的间距对称。

答案2

\documentclass{article}
\usepackage[nodisplayskipstretch]{setspace} \setstretch{1.5}
\let\oldv\verbatim
\def\verbatim{\par\setstretch{1}\oldv}
\begin{document} 
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Proin nibh augue, suscipit a, scelerisque sed, lacinia in, mi. Cras vel lorem. Etiam pellentesque aliquet tellus. Phasellus pharetra nulla ac diam.
\begin{verbatim}
A = 5
B = 123
C = 123123
\end{verbatim}
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Proin nibh augue, suscipit a, scelerisque sed, lacinia in, mi. Cras vel lorem. Etiam pellentesque aliquet tellus. Phasellus pharetra nulla ac diam.
\end{document} 

相关内容