Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In my file I need to use 1.5 line stretch. But, as for verbatim I need it to be 1.0. What should I add to preamble to achieve that?

\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} 
share|improve this question

2 Answers 2

up vote 6 down vote accepted

I suggest another improvement:

\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}}

The first \preto does almost the same as David's trick, but it also saves the value of \baselinestretch that we use also at the end of the environment for making the spacing around the verbatim environment symmetric.

share|improve this answer
\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} 
share|improve this answer
    
stretch does not apply to first para?? And how come it does not need to be restored at end of the environment sine you adjust it before beginning the environment? –  Peter Grill May 22 '12 at 21:50
1  
@PeterGrill The call \begin{foo} issues \begingroup before executing \foo. So `\setstretch{1} is executed inside the environment. –  egreg May 22 '12 at 21:56
1  
A \par should be added before \setstretch{1}. –  egreg May 22 '12 at 22:00
    
David's solution doesn't work with my edited example. It changes stretching of the first paragraph. –  Ichibann May 22 '12 at 22:01
    
Oh, it works with egreg's improval. –  Ichibann May 22 '12 at 22:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.