TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from stackoverflow.com Mar 8 '13 at 23:44

This question came from our site for professional and enthusiast programmers.

\@startsection initiates itself with \par and therefore allows for a page break before the sectional header. Specific to your code snippet, \section attempts to avoid a page break after it, but \subsection allows a page break before it. – Werner Mar 8 '13 at 19:52
@Hendrik, I would suggest reverting back to the original definitions and changing bit by bit to what you want it to look like, with incremental compilation. You should be able to find your error that way (unless it is actually rooted somewhere else in your custom class). – Sean Allred Mar 9 '13 at 0:19
@Werner Could you tell me which part specifically in \section attempts to avoid a page break after it? Is it the 2ex \@plus.2ex? I'd like to understand that. – macmadness86 Jun 12 '15 at 8:53
In latex.ltx you'll find the definition of \@startsection-used by all sectioning commands in the default sense. At the start of \@startsection you'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 \@xsect where you'll see a \par\nobreak. \nobreak avoids 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
up vote 5 down vote accepted

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.

share|improve this answer
I would like to know how to do this with titlesec, so I asked a new question here: tex.stackexchange.com/questions/253887/… – macmadness86 Jul 6 '15 at 8:52

If you want to prevent a page break put your text, section headings, etc. into a samepage area.

% page break may occur here
\subsection{Getting started}

Now section and subsection should always be on the same page.

However, if you place a \label in the section/subsection, but outside the samepage environment, references to the label will show the number of the previous section!

share|improve this answer
Do NOT do this if you have labels in the section. If you put a label into the subsection whose heading is in the samepage environment, without including the label itself in the samepage environment, references to the label will bear the number of the previous section! – Jan Schejbal Jun 29 '14 at 18:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.