[Tex/LaTex] Increase title spacing stretchability using titlesec with compact

sectioningspacingtitlesec

I have a two-column document that uses the titlesec package with the compact option. This mostly produces the spacing that I like, but it doesn't give enough stretchability above the section titles which leads to underfull vboxes and spaces between paragraphs. It is especially noticeable in pages that have full-width floats and only one column of text has a heading (e.g., \paragraph).

Is there any easy way to increase the stretchability without just guessing values for \titlespacing?

Minimal example.

\documentclass{article}
\usepackage[compact]{titlesec}
\usepackage{lipsum}
\beforetitleunit=1in % lockstep's suggestion (more or less)
\begin{document}
\section{A}
\lipsum[1]
\subsection{B}
\lipsum[2]
\subsubsection{C}
\lipsum[3]
\paragraph{D}
\lipsum[4]
\end{document}

Best Answer

Looking into titlesec.sty, the following code lines seem to define a "building block" for the spacing before and after headings (the actual spacing is determined by applying a multiplier):

\newskip\beforetitleunit
\beforetitleunit=1ex\@plus.3ex\@minus.06ex
\newskip\aftertitleunit
\aftertitleunit=1ex\@plus.1ex

So try to double the stretchability before headings by adding the following to your preamble:

\makeatletter
\beforetitleunit=1ex\@plus.6ex\@minus.12ex
\makeatother

EDIT: It seems that one must add \titlespacing in order to implement the changes to \beforetitleunit. The following should work and produce "compact" spacing with double stretchability:

\documentclass{article}
\usepackage[compact]{titlesec}
\makeatletter
\beforetitleunit=1ex\@plus.6ex\@minus.12ex
\makeatother
\titlespacing*{\section}{0pt}{*1}{*1}
\usepackage{lipsum}
\begin{document}
\section{A}
\lipsum[1]
\section{B}
\lipsum[1]
\subsection{Ba}
\lipsum[1]
\end{document}
Related Question