12

I am using the "setspace" package to format my document with double spacing (requirement for an assignment). One of my section headers takes up two lines, though, and these section headers look better with single spacing. I went ahead and fixed it with the following.

Nunc venenatis nulla eu arcu pellentesque eu molestie nunc condimentum.
Donec sodales lacinia dictum.
Sed aliquam turpis quis enim bibendum pharetra.
This is the last paragraph in section i.

\singlespace
\section{The Next Section Which Has a Fairly Long Name that Stretches Over Two Lines}
\doublespace
This is the first paragraph in section i+1.
Cras ut tortor vel dui ultricies dapibus vitae sit amet nisi.
Aliquam rhoncus leo id eros volutpat faucibus.
Integer lectus elit, varius et semper eget, tristique vel odio.

This is the only case (so far) in my paper where the heading requires two lines, so it's not a big deal to fix it with this hack. However, I can imagine as the paper gets longer and has more sections, it could become more tedious to add this hack multiple times.

Is there any way I can indicate once that section headings should be single-spaced and paragraphs should be double-spaced, rather than adding this hack multiple times throughout my document?

  • 1
    I think that \let\OldSection\section \renewcommand*{\section}[1]{\singlespace\OldSection{#1}\doublespace} will give you the results you are looking for. – Peter Grill Apr 2 '13 at 3:06
  • 1
    @PeterGrill be careful! With your redefinition you loose the optional argument for \section. – Gonzalo Medina Apr 2 '13 at 3:13
  • 1
    @GonzaloMedina: Yeah, always forget about those -- plus you beat me to it, so your answer is better. So probably better to use \usepackage{letltxmacro} \LetLtxMacro\OldSection\section \renewcommand*{\section}[2][]{\singlespace\OldSection[#1]{#2}\doublespace}. – Peter Grill Apr 2 '13 at 3:16
  • @PeterGrill that will also produce problems with an eventual \tableofcontents. – Gonzalo Medina Apr 2 '13 at 3:25
  • 1
    @GonzaloMedina: Hmmm.. that seems like a good follow up question as I can't see why it would effect the TOC. – Peter Grill Apr 2 '13 at 3:35
13

You can use the etoolbox package to insert \singlespacing just before the sectional units, and then to append \doublespacing:

\documentclass{article}
\usepackage{setspace}
\usepackage{etoolbox}

\makeatletter
\pretocmd{\@sect}{\singlespacing}{}{}
\pretocmd{\@ssect}{\singlespacing}{}{}
\apptocmd{\@sect}{\doublespacing}{}{}
\apptocmd{\@ssect}{\doublespacing}{}{}
\makeatother

\doublespacing

\begin{document}

Nunc venenatis nulla eu arcu pellentesque eu molestie nunc condimentum.
Donec sodales lacinia dictum.
Sed aliquam turpis quis enim bibendum pharetra.
This is the last paragraph in section i.

\section{The Next Section Which Has a Fairly Long Name that Stretches Over Two Lines}

This is the first paragraph in section i+1.
Cras ut tortor vel dui ultricies dapibus vitae sit amet nisi.
Aliquam rhoncus leo id eros volutpat faucibus.
Integer lectus elit, varius et semper eget, tristique vel odio.

\end{document}

enter image description here

This will apply to \section, \subsection, \subsubsection.

Another option is to use the titlesec package:

\documentclass{article}
\usepackage{setspace}
\usepackage{titlesec}

\titleformat{\section}
{\singlespacing\normalfont\Large\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}
{\singlespacing\normalfont\large\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\singlespacing\normalfont\normalsize\bfseries}{\thesubsubsection}{1em}{}

\doublespacing

\begin{document}

Nunc venenatis nulla eu arcu pellentesque eu molestie nunc condimentum.
Donec sodales lacinia dictum.
Sed aliquam turpis quis enim bibendum pharetra.
This is the last paragraph in section i.

\section{The Next Section Which Has a Fairly Long Name that Stretches Over Two Lines}

This is the first paragraph in section i+1.
Cras ut tortor vel dui ultricies dapibus vitae sit amet nisi.
Aliquam rhoncus leo id eros volutpat faucibus.
Integer lectus elit, varius et semper eget, tristique vel odio.

\end{document}

Or, using the reduced syntax:

\usepackage{titlesec}

\titleformat*{\section}{\normalfont\Large\bfseries\singlespacing}
\titleformat*{\subsection}{\normalfont\large\bfseries\singlespacing}
\titleformat*{\subsubsection}{\normalfont\normalsize\bfseries\singlespacing}

By the way, the setspace package provides several commands and environments; the commands (switches) end in "ing": \singlespacing, \onehalfspacing, \doublespacing, whereas the environments are singlespace, onehalfspace, doublespace.

Using \doublespace are you are doing (as a switch) is not entirely correct; the following simple document:

\documentclass{article}
\usepackage{setspace}

\doublespace

\begin{document}

test

\end{document}

when processed will show in the output console a message

(\end occurred inside a group at level 1)

### semi simple group (level 1) entered at line 4 (\begingroup)

which indicates that a group started but was never ended (in this case, the group created by the \doublespace command associated to the environment doublespace). The correct form of using the switch is

\documentclass{article}
\usepackage{setspace}

\doublespacing

\begin{document}

test

\end{document}

and, for the corresponding environment:

\documentclass{article}
\usepackage{setspace}

\begin{document}

\begin{doublespace}
test...
\end{doublespace}

\end{document}
1

If one of the "standard" document classes -- article, report, and book -- or a document class that's based on one of the standard classes is in use, a straightforward solution consists in loading the sectsty package and issuing the instruction \allsectionsfont{\singlespacing} in the preamble.

An MWE (minimum working example):

\documentclass{article}
\usepackage{setspace,lipsum}
\doublespacing

\usepackage{sectsty}
\allsectionsfont{\singlespacing}

\begin{document}

\lipsum[1] % filler text

\section{The Next Section Which Has a Fairly Long Name that Stretches Over Two Lines}

\lipsum[2] % more filler text

\end{document}

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.