I set spacing between lines in my text with \linespread{1.3} command, so my
page fits the standards of my university.
In some pages I need to include some C code, so I used the verbatim
environment, and everything I wrote inside this environment has the same
space between lines the other text has. This is normal, because I told LaTeX
to do so, but this looks ugly! Can I set a different spacing between lines
only inside Verbatim environment?
I tried:
\linespread{1}
\small
\begin{verbatin}
...
\end{verbatim}
\normalsize
\linespread{1.3}
This works only if I have one verbatim environment, as well as I write the
second one, the text outside verbatim gets the wrong spacing between lines.
Thanks in advance, sorry if this is a silly question, since I'm a LaTeX
newbie.
Bye,
Aldo
> I tried:
> \linespread{1}
> \small
> \begin{verbatin}
> ...
> \end{verbatim}
> \normalsize
> \linespread{1.3}
> This works only if I have one verbatim environment, as well as I write the
> second one, the text outside verbatim gets the wrong spacing between lines.
What you describe should not happen. Do you have some very old
version of LaTeX? Or do you *really* type
\renewcommand{\baselinestretch}{1.3}
instead of
\linespread{1.3} ?
You can do
\linespread{1}
\small
\begin{verbatin}
...
\end{verbatim}
\linespread{1.3}
\normalsize
(The linespread is applied when the font changes.)
You can use the verbatim package, and put these settings
into a new verbatim-style environment, or even better,
use the listings package.
Finally, even with very pld LaTeX, you could redefine
\verbatim@font to set the line spacing to 1.
Donald Arseneau as...@triumf.ca
> What you describe should not happen. Do you have some very old
> version of LaTeX? Or do you *really* type
> \renewcommand{\baselinestretch}{1.3}
> instead of
> \linespread{1.3} ?
I use the LaTeX distribution I found in my Mandrake Linux 7.2 installation.
I typed \linespread{1.3}, because I found it on tutorial on the net.
> You can do
>
> \linespread{1}
> \small
> \begin{verbatin}
> ...
> \end{verbatim}
> \linespread{1.3}
> \normalsize
>
> (The linespread is applied when the font changes.)
I made some other experiments, and I noticed that when I omit the font size
change commands everyting works fine,
and everything works fine even if I change once in a page the font size
with \small and \normalsize.
If in a page I have two verbatims and before each one I set \small and after
each one I set \normalsize the whole page (including non-verbatim text,
between the 2 verbatims and also before the first) gets the shorter
specified linespread.
I also noticed, in package setspace.sty, that defines command for single,
double and "one and an half" spacing, that the author, after issuing the
command \linespread{1} also issues the commands "\vskip \baselineskip".
I don't understand what this means, I am not a LaTeX expert...
I also tried exchanging the relative position of \linespread and \small and
\normalsize, I nearly got it to work, but if I enlarge the screen I can see
the space between lines of my text is 1-2 pts smaller than what I can see in
the previous pages, and so this does't suit my needs.
the problem is that "paragraph" parameters are frozen at the end of a
paragraph: changing font size within a paragraph is always
problematical since whatever happens, the line spacing used for the
whole paragraph is that selected at the end of the paragraph. this is
perfectly visible (and was the subject of an article in tugboat a
while back, by jeremy gibbons) even if the change of line spacing
derives simply from a change in font size.
i can't remember what jeremy proposed to deal with the problem (he was
considering small verbatim too, as it happens). i think the following
would work, though it's untested...
\def\verbatim@font{\linespread{1.0}\small\ttfamily}
\def\endverbatim{\if@newlist \leavevmode\fi\par\endtrivlist}
(all to be enclosed in \makeatletter ... \makeatother if not in a
package or class file).
>I also noticed, in package setspace.sty, that defines command for single,
>double and "one and an half" spacing, that the author, after issuing the
>command \linespread{1} also issues the commands "\vskip \baselineskip".
>I don't understand what this means, I am not a LaTeX expert...
it means "insert a modified inter-line skip at this point". dunno
why, without looking at the code.
>I also tried exchanging the relative position of \linespread and \small and
>\normalsize, I nearly got it to work, but if I enlarge the screen I can see
>the space between lines of my text is 1-2 pts smaller than what I can see in
>the previous pages, and so this does't suit my needs.
the whole thing is determined by the two slightly unexpected factors:
1. that \linespread doesn't take effect until the next font change (so
you always need it before the \small or \normalsize command
2. its relation to the presence of \par commands in your document is
crucial.
the latter point is dealt with by my changes above. there's a \par
inside \begin{verbatim} so the change of \linespread in \verbatim@font
is safe, and since i've inserted a \par inside \end{verbatim}, the
verbatim text gets set with the correct linespread.
(always supposing, of course, that my patches work...)
--
Robin Fairbairns, Cambridge -- rf10 at cam dot ac dot uk
> I made some other experiments, and I noticed that when I omit the font size
> change commands everyting works fine,
OK, I think I understand now. All the other experiments and
results you report are bogus :-)
What you are doing is setting the size before ending the previous
paragraph, and therefore setting the linespacing for the previous
paragraph. Leave a blank line before
\linespread{1}\small
\begin{verbatim}
and still end with
\end{verbatim}
\linespread{1.3}\normalsize
(No need for blank line here, unless you want indentation.)
I thought \linespread applied immediately these days... I will
have to check.
Donald Arseneau as...@triumf.ca
I could solve my problem.
It this can be of interest I solved my problem using the
"fancyvrb" package, with these commands:
[...]
\linespread{1}
\begin{Verbatim}[fontsize=\small]
[...]
\end{Verbatinm}
\linespread{1.3}
Now everything works fine!
Your answer made me understand a bit more of LaTeX behavior, I was
suspecting that font size and paragraph definitions were involvede, but I
couldn't figure out how.
I think I'll also try as you suggested.
Goodbye,
Aldo
"Donald Arseneau" <as...@triumf.ca> ha scritto nel messaggio
news:yfid71z...@triumf.ca...
> "Aldo" <al...@somewhere.net> writes:
>
> > I tried:
> > \linespread{1}
> > \small
> > \begin{verbatin}
> > ...
> > \end{verbatim}
> > \normalsize
> > \linespread{1.3}
> > This works only if I have one verbatim environment, as well as I write
the
> > second one, the text outside verbatim gets the wrong spacing between
lines.
>
> What you describe should not happen. Do you have some very old
> version of LaTeX? Or do you *really* type
> \renewcommand{\baselinestretch}{1.3}
> instead of
> \linespread{1.3} ?
> [...]