2

To format headings I am using the titlesec package. I need 12 pt space before each heading and 6 pt after. If there are consecutive headings (i.e. heading directly followed by subheading) I need 12 pt space between them. Therefore, I use the package option largestsep. However, the space between two headings is more than 12 pt. Am I missing something?

Quote from the titlesec documentation: "By default, when there are two consecutive titles the aftersep space from the first one is used between them. […] With largestsep the largest of them is used.”)

MWE:

\documentclass{article}
\usepackage{lipsum}
\usepackage[largestsep]{titlesec}
\titlespacing {\section} {0pt} {12pt} {6pt}
\titlespacing {\subsection} {0pt} {12pt} {6pt}
\begin{document}
\section{Section}
\subsection{Subsection}
\lipsum
\end{document}

1 Answer 1

2

You are right in saying this doesn't work. It looks like a bug to me. Adding \unskip after the first title restores the behaviour, removing a spurious vertical skip of zero size that is inserted in the output and preventing the internal \addvspace having any effect. I don't know where this extra zero space is generated.

In the code below, \showoutput tells us that the \unskip variant results in

...\glue 6.0
...\glue -6.0
...\glue 12.0

as desired, whereas without the \unskip we get

...\glue 6.0
...\glue 0.0
...\glue 12.0

Sample output

\documentclass{article}

\usepackage{lipsum}
\usepackage[largestsep]{titlesec}
\titlespacing{\section}{0pt}{12pt}{6pt}
\titlespacing{\subsection}{0pt}{12pt}{6pt}

\begin{document}
\showoutput
\section{Section}\unskip
\subsection{Subsection}
\lipsum[1]
\section{Section}
\subsection{Subsection}
\lipsum[2]
\end{document}

Update: thanks to Ruixi Zhang the source of the zero skip has been identified. The titlesec code uses LaTeX's \vspace which is essentially the required \vskip followed by a second zero \vskip. Changing \vspace to \vskip in the appropriate internal function gives the desired behaviour. Here is a local patch via etoolbox:

\documentclass{article}

\usepackage{lipsum}

\usepackage{etoolbox}
\usepackage[largestsep]{titlesec}
\titlespacing{\section}{0pt}{12pt}{6pt}
\titlespacing{\subsection}{0pt}{12pt}{6pt}

\makeatletter
\patchcmd{\ttl@straight@ii}{\vspace{\@tempskipb}}{\vskip\@tempskipb}{}{}
\makeatother

\begin{document}

\showoutput
\section{Section}
\subsection{Subsection}
\lipsum[1]
\section{Section}
\subsection{Subsection}
\lipsum[2]
\end{document}

producing glue sequence

...\glue 6.0
...\glue -6.0
...\glue 12.0

as wished and resulting in

enter image description here

8
  • Thx! Any idea for a global workaround?
    – Janine
    Oct 8, 2015 at 10:00
  • Not currently, I have not yet tracked down the source of the extra zero skip. Oct 8, 2015 at 16:13
  • any new on this?
    – Janine
    Dec 11, 2015 at 15:38
  • 1
    @AndrewSwann The extra zero skip comes from \vspace since LaTeX2e kernel defines \vspace{#1} to expand to ... \vskip #1 \vskip\z@skip ... Apr 25, 2020 at 20:51
  • 1
    @Janine Bug report filed along with proposed fixes: github.com/jbezos/titlesec/issues/27 Apr 25, 2020 at 21:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .