# Absolute vertical position of text after chapter title

does anyone know the most elegant way of obtaining a dynamic vertical space after the chapter title according to the number of lines the title takes?

I want the text body to always start at the same vertical position, regardless of whether the chapter title stretches over 1/2/3 lines.

The standard infrastructure such as \renewcommand*{\chapterheadendvskip} or

\titlespacing{<command>}{<left>}{<before-sep>}{<after-sep>}[<right>]


from the titlesec package only allows for a relative vertical spacing.

So I need something like

\renewcommand*{\chapterheadendvskip}{\vskip\dimexpr 35mm-\n\baselineskip}


where \n is the number of lines the concrete chapter title takes.

MWE:

\documentclass{scrbook}
\usepackage{lipsum}

\begin{document}

\lipsum[1]

\chapter{This is a very very long headline taking two or more lines making the
text shift down accordingly}
\lipsum[1]

\end{document}


Thanks a lot!

• titlesec has a package option called rigidchapters which does what you want. But then, I think KOMA does not play nicely with it. Can you use a standard document class? – Arash Esbati Jan 10 '17 at 18:20
• Nice idea! But the problem is, I'm stuck to scrbook. – LaTechneuse Jan 10 '17 at 19:25

You can redefine \chapterlinesformat:

\documentclass{scrbook}
\usepackage{lipsum}

\RedeclareSectionCommand[afterskip=35mm]{chapter}

\makeatletter
\renewcommand*{\chapterlinesformat}[3]{%
\parbox[t][0pt][t]{\linewidth}{\raggedchapter\@hangfrom{#2}{#3}}%
}
\makeatother

\begin{document}

\lipsum[1]

\chapter{This is a very very long headline taking two or more lines making the
text shift down accordingly}
\lipsum[1]

\end{document}


If you need the top edge of the first line of the chapter head aligned with top edge of the text area, you need an extra \par at the end of \chapterlinesformat. But then an extra height of the first line of the chapter head (e.g. something like \rule{2cm}{2cm}) could move the text after the chapter head down. You can avoid this using some extra \parbox and \strut magic:

\documentclass{scrbook}
\usepackage{lipsum}
\usepackage{showframe}% show the text area for debugging

\RedeclareSectionCommand[%
beforeskip=-1sp,% no space or glue before the chapter head and no indent of
% the first paragraph after the chapter
afterskip=35mm,% 35mm (but no glue) after the first line of the chapter head
]{chapter}

\makeatletter
\renewcommand*{\chapterlinesformat}[3]{%
\parbox[t][\ht\strutbox][t]{\linewidth}{\strut
\parbox[t][0pt][t]{\linewidth}{%
\vskip -\ht\strutbox
\raggedchapter\@hangfrom{#2}{\strut #3}}\par
}%
}
\makeatother

\begin{document}

\lipsum[1]

\chapter{This is a very very long headline taking two or more lines making the
text shift down accordingly}
\lipsum[1]

\chapter{\protect\rule{5em}{5em}This rule breaks everything}
\lipsum[1]

\end{document}


If you have chapters with prefix line, you have to redefine \chapterlineswithprefixformat. See the manual for more information about these commands and their defaults.

• Thanks, this is an excellent solution! Only thing is: if you compare the vertical position of the headline with and without your modification, it is not the same. The \parbox you inject puts the baseline of the headline on the first baseline of normal text. But as the font of the headline is bigger, it will grow a bit higher in consequence. The normal \chapter command however, if you set the beforeskip to 0pt, does not align the baseline of the headline with the first baseline, but the top of the headline with the top of the text area. Dunno how to solve this to get the same result... – LaTechneuse Jan 10 '17 at 22:49
• You can add \par\nobreak to the end of \chapterlinesformat. – Schweinebacke Jan 11 '17 at 7:23

If you're not stuck to the scrbook class, the titlesec package has the rigidechapters for that.

Example:

\documentclass[a4paper,  openany]{book}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[showframe]{geometry}
\usepackage{microtype}
\SetTracking[no ligatures={f}]{encoding=*}{50}
\usepackage{lipsum}
\usepackage[newlinetospace, rigidchapters]{titlesec}%
\titleformat{\chapter}[display]
{\sffamily\bfseries\LARGE\filleft} %\normalsize
{{\Huge\thechapter}\vspace{0.5ex}\\
\titlerule[1.5pt]}%
{0ex}
{\lsstyle}%

\titlespacing{\chapter}{0pt}{0.5cm}{6cm}
\begin{document}

\chapter{Introduction}
\lipsum[1-3]

\chapter{Particles Interaction\\ with Multiphase Fluid \\ and the Applications}

\lipsum[5-8]
\end{document}


• Thanks for this solution. But the problem is, I'm stuck to scrbook. – LaTechneuse Jan 10 '17 at 19:24
• I'm not sure titlesec is fully compatible with komascript., and I don't know if it has similar tool as the rigidchapters option. Note the effect of this option is the last parameter of titlespacing is the vertical distance between the top of the title and the following text, whereas the default is the distance between the bottom of the title and the following text (hence greater values in the former case). – Bernard Jan 10 '17 at 19:42