# Reducing the line spacing of multi-line section headings in memoir

[This is essentially a memoir-specific version of this question.]

How can I reduce the line spacing within section (or other) headings in memoir without affecting the spacing to the body text above?

In the example that follows, modifying \baselineskip does the trick but also affects the spacing of the heading to the previous section's body text. I would like to get rid of this unintended side effect.

Further notes about my example: Note that halving \baselineskip is too much, but it's good for illustrating the issue. I've included \tableofcontents and used the optional-argument version of \section (\section[what appears in the TOC]{what appears in the document body}) to draw attention to the fact that whatever modifications of the section heading we make, we probably don't want to affect the table of contents. For those taking issue with the visuals of the example ("The original line spacing is just fine in what you show below!"), the actual problem is from something else (my other, actual document has horrible double-spacing); update: I have included a screenshot for that as well.

Notes for those helping with a solution: 1. It seems that \par can't be issued within a section heading. 2. \setstretch (from the solutions to the linked question) doesn't work within memoir.

This issue is exacerbated by doublespacing (add \DoubleSpacing in the preamble):

\documentclass[12pt]{memoir}

%\DoubleSpacing

\begin{document}

\tableofcontents

Look at the distance of this line to the following heading (as intended):

\section{This is a section heading spanning two lines}

Look at the distance of this line to the following heading (slightly too small):

\section[This is a section heading spanning two lines]%
{\setlength{\baselineskip}{0.5\baselineskip}%
This is a section heading spanning two lines}

Text.

\end{document}

• The way you can fix this manually is to re-introduce the correct \baselineskip in the form of a strut. That is, insert \rule{0pt}{22pt} at the start of the section title (22pt = \baselineskip within \section). – Werner Apr 25 '14 at 7:11
• Just specify the font size and baseline skip in the configuration of the sections look (\setsecheadstyle), remember the two arguments of \fontsize – daleif Apr 25 '14 at 11:14
• @daleif But how do I remember what the 2 effective arguments of \fontsize would be? Also my actual document has \DoubleSpacing in the preamble. Could you try writing an answer? – Lover of Structure Apr 25 '14 at 12:38
• That is even worse, please update your example. The I'll have a look when I'm at a computer. Btw, if the doc is suppose to be double spaced, then why not the section titles? – daleif Apr 25 '14 at 15:07
• @daleif I've updated my example, though - as originally described - there wasn't much to update. – Lover of Structure Apr 25 '14 at 20:34

Double spacing is the worst setting one can apply to a document. I know that some stubborn secretary in the offices of universities keep asking for such typographic horrors that might have been justified in the olden days of typewritten theses, but nowadays have no reason.

End of rant.

I wouldn't reduce the interline space in headings beyond normal (single spaced), but a small reduction can be done; after all, with a double spaced document, this is just a very minor sin.

\documentclass[12pt]{memoir}
\usepackage{lipsum}

\DoubleSpacing

\begin{document}

\tableofcontents

Look at the distance of this line to the following heading (as intended)

\section{This is a section heading spanning two lines}

\lipsum[3]

\end{document}


• I entirely agree with the rant part. – Lover of Structure Apr 26 '14 at 0:35
• Interesting; \setSpacing isn't documented in the memoir manual. – Lover of Structure Apr 26 '14 at 0:36
• I was gonna try something with \let\oldsecheadstyle\secheadstyle \setsecheadstyle{ something \oldsecheadstyle}, which is the same as looking up the original definition of \secheadstyle and then prepending something (like you did). However your solution does affect the spacing of the heading to the body text before; I was looking for an approach that leaves that untouched. – Lover of Structure Apr 26 '14 at 0:39
• @LoverofStructure You can use \preto of etoolbox. For the spacing, it's obvious that modifying the leading will also need an adjustment of \beforesecskip. – egreg Apr 26 '14 at 9:00
• In a \DoubleSpacing context, \baselineskip with and without \setSpacing{1} (no need for the \setSpacing{0.95} you used in your example) is 22.0pt and 36.40997pt within a section heading. Writing \addtolength{\beforesecskip}{14.40997pt} \section[This is a section heading spanning two lines]{\setSpacing{1}This is a section heading spanning two lines} \addtolength{\beforesecskip}{-14.40997pt} actually reduces the spacing of the heading to the text before by a fair amount. Any ideas what may be going wrong? – Lover of Structure Apr 26 '14 at 21:26

The simple answer (for a \DoubleSpacing context):

\preto{\secheadstyle}{\setSpacing{1}} % requires package "etoolbox"


The adjustment for \beforesecskip is negative because \beforesecskip is already negative and, as user egreg points out, a negative skip is used in its positive/absolute value but is given in a negative number to indicate that the paragraph after the title will not be indented.

Naturally, the adjustment required for \beforesecskip in order to keep the spacing of the heading to any text before the heading constant depends on one's document spacing (here \DoubleSpacing) and on the reset of the spacing (here 1, as fed to the memoir-internal \setSpacing macro). One can compute this value manually as follows: memoir's \DoubleSpacing executes \setSpacing{1.655} for 12pt, and we can calculate 22pt*(1.655-1)=14.41pt, where \baselineskip=22pt within the section heading for normal single spacing. The cause for the 22pt is the invocation of \secheadstyle for the section heading. The official way to modify \secheadstyle is via \setsecheadstyle, but I'm keeping things as general as possible and simply prepend my change via etoolbox's \preto.

I will demonstrate that this works, but by making manual adjustments, contrasting "no adjustment" with "adjustment", for non-page-initial as well as page-initial section headings. The following screenshot shows a contrast in a non-page-initial scenario, where the distance of the section heading to the immediately preceding text is identical for both (due to my adjustment to \beforesecskip):

\documentclass[12pt]{memoir}
\usepackage{calc}

\DoubleSpacing

\begin{document}

\tableofcontents

\newlength{\secbaselineskip}
\newlength{\secbaselineskipDiff}
{
\setlength{\secbaselineskip}{\the\baselineskip}%
\global\secbaselineskip=\secbaselineskip
% evaluates to 36.40997pt
\setSpacing{1}
% evaluates to 22.0pt
}
% evaluates to 14.40997pt

\newpage

\noindent
Text.

\section{This is a section heading spanning two lines}

Text.

\section[This is a section heading spanning two lines]{\setSpacing{1}\relax
This is a section heading spanning two lines}

Text.

\newpage
\section{This is a section heading spanning two lines}

Text.

\newpage

In the computation of the difference in \baselineskips I use a trick by Heiko Oberdiek, as channeled by Andrew Swann: \global\setlength doesn't work with calc, but writing \setlength{\mylength}{...}\global\mylength=\mylength circumvents that.
[Much credit for the solution goes to egreg.]