[Tex/LaTex] How to prevent page break between two section headings


I have a custom document class, based on book.cls, for which the following code sometimes produces page breaks between two subsequent sections:

  % 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}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {2ex \@plus .2ex}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {2ex \@plus .2ex}%
% etc.

Any ideas what might cause LaTeX to allow a page break?

Best Answer

The problem is that \color{MMIblue} inserts a whatsit that disrupts the mechanism for disallowing page breaks after sectional titles.


    {-3.5ex \@plus -1ex \@minus -.2ex}%
    {2ex \@plus.2ex}%

which works because the last instruction in the sixth argument to \@startsection reads the section title (with the number) as a braced group, which can then be interpreted by \textcolor as its second argument.