17

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

  • Add \usepackage{setspace} and use \begin{doublespacing} ... \end{doublespacing}. Note that the documentation (as such) is located within setspace.sty itself. – jon Jul 4 '13 at 19:09
  • Related: linespacing without packages – Werner Jul 4 '13 at 19:24
  • How are you managing those lines of code? – egreg Jul 4 '13 at 19:43
17

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.

  • 1
    unfortunately, the spacing above and below the "expanded" paragraph is not the same (and i don't know, without experimenting, how to make it so). the impression this gives is that there's some difference in meaning at the two paragraph breaks -- in addition to what's implied by the spread lines. my inclination is that the spacing should be "wide" both before and after. it would be nice to have this built into the routine. – barbara beeton Jul 4 '13 at 20:45
  • 1
    @barbarabeeton: I've added some detail to that effect. – Werner Jul 4 '13 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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