I have a custom document class, based on book.cls, for which the following code sometimes produces page breaks between two subsequent sections:
\section{Introduction}
% page break may occur here
\subsection{Getting started}
I am completely puzzled, because my definitions for the sectioning commands are almost identical to those in book.cls:
\newcommand \headingfont {\fontfamily{phv}\fontseries{bc}\fontshape{n}\selectfont}
\newcommand\section{\@startsection {section}{1}{\headerindent}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2ex \@plus.2ex}%
{\color{MMIblue}\headingfont\Large}}
\newcommand\subsection{\@startsection{subsection}{2}{\headerindent}%
{-3.25ex\@plus -1ex \@minus -.2ex}%
{2ex \@plus .2ex}%
{\color{MMIblue}\headingfont\large}}
\newcommand\subsubsection{\@startsection{subsubsection}{3}{\headerindent}%
{-3.25ex\@plus -1ex \@minus -.2ex}%
{2ex \@plus .2ex}%
{\color{MMIblue}\headingfont\normalsize}}
% etc.
Any ideas what might cause LaTeX to allow a page break?
\@startsectioninitiates itself with\parand therefore allows for a page break before the sectional header. Specific to your code snippet,\sectionattempts to avoid a page break after it, but\subsectionallows a page break before it. – Werner Mar 08 '13 at 19:52\sectionattempts to avoid a page break after it? Is it the2ex \@plus.2ex? I'd like to understand that. – Jonathan Komar Jun 12 '15 at 08:53latex.ltxyou'll find the definition of\@startsection-used by all sectioning commands in the default sense. At the start of\@startsectionyou'l see an issue of\par, which should allow for a possible page-break. However, at the end the entire sectional unit setting (you have to follow the command sequence) it executes\@xsectwhere you'll see a\par\nobreak.\nobreakavoids a page-break. This is conditional on whether you have a display or run-in section. The former doesn't insert a vertical space so avoids a break. – Werner Jun 12 '15 at 16:10