[Tex/LaTex] Linespacing LaTeX for just a few lines

line-spacingpackagesspacing

How can I increase the linespacing for just a few lines of code in LaTex?

Best Answer

The setspace package provides the means the change the line spacing in a very consistent (and easy) way trough environments or by a switch. Here's a small example:

enter image description here

\documentclass{article}
\usepackage{setspace}% http://ctan.org/pkg/setspace
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\lipsum[1]

\begin{doublespacing}
\lipsum[1]
\end{doublespacing}

\lipsum[1]
\end{document}

Note that there is some hidden information in the above example. Since LaTeX sets text on a paragraph basis, you need to ensure that you initiate a paragraph break (through an empty line or an explicit \par) in order for the line-spacing to take effect. This is implicitly done by the lipsum package's \lipsum command above.

Switches should be grouped to limit the scope using something like

%...

\begingroup\onehalfspacing
% some paragraph text
% (maybe end with \par)
\endgroup

%...

Switches and environment provided by setspace are

  • sinĀ­glespacĀ­ing
  • onehalfspacing and
  • doublespacing.

However, the more general \setstretch{<num>} macro is the required interface for doing more general line-space setting.

setspace provides the interface with elements like \baselineskip and \linespread. See Why is the \linespread factor as it is? for a general discussion on the choice of <num>.


Barbara mentioned the option of having an "equally wide" gap above/below the increased line spacing paragraph. The reason why it's not is because the \baselineskip is paragraph-based. So, the paragraph following the change has a different (smaller) \baselineskip, and is therefore visually closer. A naive approach to correct for this is given below using some "fudging":

enter image description here

\documentclass{article}
\usepackage{setspace}% http://ctan.org/pkg/setspace
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\newlength{\fudgeheight}
\newcommand{\fudgestrut}{\leavevmode\rule{0pt}{\fudgeheight}}
\begin{document}
\lipsum[1]

\begin{doublespacing}
\lipsum[1]\global\setlength{\fudgeheight}{\baselineskip}
\end{doublespacing}

\fudgestrut\lipsum[1]
\end{document}

The idea here is to insert a vertical strut - \fudgestrut - using the increased \baselineskip within the first line of the paragraph following the line spacing change. I'm sure this process can be automated somewhat, but the use-case doesn't warrant such investigation.

Related Question