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}
\setsecheadstyle{\centering\Large\normalfont\noindent}
\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}




<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 02:16\beforeXscipare a memoir specific thing. They prevent indentation after the title. See: https://tex.stackexchange.com/questions/15856 – user5950 Sep 18 '18 at 08:01