# True grid: What happens to vertical spaces if a section follows directly a chapter?

I am trying to keep the lines of all pages to the same grid. So I set the spaces above and under \chapter, \section etc. to compensate the different baselineskip of my headings.

For example I set the \beforechapskip to 3.5\onelineskip as the fontsize of chapter is set to \LARGE which in memoir means it has a baselineskip of 18pt (18pt - \onelineskip = 6pt).

And I set \beforesecskip to -2\onelineskip + 2.5pt to compensate the section font size \large, from which results a baselineskip of 14.5pt

But I have some trouble to understand how LaTeX treads the vertical spaces above and under \chapter, \section etc. under different circumstances: As this seems to result in a perfect grid except if a section follows directly a chapter.

Why? I would expect LaTeX to eat the space above the section giving me the same result as if the section is set to the top of the page. But this is not the case, instead it is set 2.5pt lower than the grid.

What can I do? The only solution I came up with, was to redefine the chapter command putting something like this at its end:

\@ifnextchar\section{\vspace*{-2.5pt}}{}%


But this would work only if no newline is between chapter and section and it seems to be a messy solution anyway.

Here is a minimal working example:

\documentclass[a4paper,10pt,twoside]{memoir}
\usepackage{calc}
\usepackage{lipsum}
\setlength{\parskip}{0pt plus 0pt minus 0pt}
\renewcommand{\chapnamefont}{\centering\normalfont}
\renewcommand{\chapnumfont}{\centering\normalfont}
\setlength{\midchapskip}{\onelineskip}
\setlength{\afterchapskip}{2\onelineskip}
\setlength{\beforechapskip}{3.5\onelineskip}

\renewcommand*{\printchapternonum}{\vspace{2\onelineskip}}

\renewcommand\chaptitlefont{\centering\LARGE\normalfont}

\setbeforesecskip{-2\onelineskip + 2.5pt}
\setaftersecskip{\onelineskip}

\begin{document}
\chapter{Test}
\section{Test}
\lipsum[2-12]
\chapter{Test what ever?}
\lipsum[2-12]
\section{Test}
\lipsum[2-11]

\newpage
\section{Don't read that sh*t1}
\lipsum[2-11]
\end{document}


Here are some screen shots:

EDIT: I found out, that a solution could be:

\setlength{\afterchapskip}{2\onelineskip  plus 0pt minus 2.5pt}

• It is worth pointing out that the <length> plus <length> minus <length> is a glue; that is, the space is stretchable and shrinkable. This may not create a “perfect grid”. – Ruixi Zhang Sep 18 '18 at 2:16
• the edit is definitely not a solution at all for grid typesetting as it re-introduces stretchy space – David Carlisle Sep 18 '18 at 7:03
• @DavidCarlisle Negative values for \beforeXscip are a memoir specific thing. They prevent indentation after the title. See: tex.stackexchange.com/questions/15856 – user5950 Sep 18 '18 at 8:01
• Oh that, that's actually core latex (but I was confused by the memoir interface to it:-) OK. – David Carlisle Sep 18 '18 at 8:04

memoir has a hook at the begin of section that one can use to inject a negative space. Don't use stretchable spaces if you want to do grid typesetting. You probably will need \raggedbottom too.

\documentclass[a4paper,10pt,twoside]{memoir}
\usepackage{calc}
\usepackage{lipsum}
\setlength{\parskip}{0pt plus 0pt minus 0pt}
\renewcommand{\chapnamefont}{\centering\normalfont}
\renewcommand{\chapnumfont}{\centering\normalfont}
\setlength{\midchapskip}{\onelineskip}
\normalfont
\setlength{\afterchapskip}{2\onelineskip}
\setlength{\beforechapskip}{3.5\onelineskip}

\renewcommand*{\printchapternonum}{\vspace{2\onelineskip}}

\renewcommand\chaptitlefont{\centering\LARGE\normalfont}

\setbeforesecskip{-2\onelineskip+2.5pt}
\setaftersecskip{\onelineskip}

\makeatletter
\newcommand\sectionblock{\if@nobreak \vskip-2.5pt\fi}
\makeatother

%to show the grid
\usepackage{returntogrid,tikz}
\begin{document}
\chapter{Test}
\section{Test}
abc
\section{Test}
TTTabc

\section{Tesy}
abc

\chapter{Tesy}
\section{Test}
abc

\chapter{Tesy}
abc
\chapter{Test}

abc
\end{document}


• I wasn't aware of this hook, which seems to be the solution. Could you explain to me, why TeX treats the section after the chapter differently as a section at the beginning of a new page? By the way, I can't get the package returntogrid working. Which Linux package do I have to install (texlive-latex-extra is installes already)? – user5950 Sep 18 '18 at 9:47
• returntogrid is quite new, you need texlive 2018 to get it with a tex system. If you want to install it manually: The sty is on ctan ctan.org/pkg/returntogrid. You only need to copy it in a place where your tex system can find it. (I only used it here to draw the red lines for the debugging). – Ulrike Fischer Sep 18 '18 at 10:03