Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

3 Answers 3

up vote 4 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

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 at 18:34

Not sure you want to hear this:

From a typographical view of point I would never write two headings directly following each other. Usual is that a normal paragraph follows an heading. If you write two headings one of them is not nessessary.

If you write a sentence after your chapter heading, your problem you asked for is gone ...

Let's look us at two examples, the first one (in my opinion wrong):

1. Chapterheading
1.1 Sectionheading
    here comes your text ... 
1.2 Sectionheading 

Much better is:

1. Chapterheading
   Explanation, why two following sections are nessessary for this chapter. 
   Please keep in mind, that you have to write 2 or more sections. Only one 
   is a very bad typographic and if you rethink your text you will be able to 
   delete your single section heading.  
1.1 Sectionheading
    Some words ...
1.2 Sectionheading 

With the second writing LaTeX trys automatically to keep heading and following paragraph together ...

share|improve this answer
In general I agree with you, but for some technical documentation your arguments wouldn't apply. (Then one could argue that one shouldn't start from the book class :-)) –  Hendrik Vogt Mar 9 '13 at 8:06
I disagree in this generality. The more formalized, the less explanatory text is needed. For example, a document on algebra might be structured like: 1. Solution of linear equations foobar 2. Solution of non-linear equations 2.1 Solution of quadratic equations barfoo 2.2 Solution of cubic and quartic equations foobarfoo 2.3 Solution of higher equations barfoobar –  Toscho Mar 9 '13 at 15:52
Hmm, it seems both Paul Renner and Robert Bringhurst disagree... At least they're both using headings and subheadings directly after each other in their books (»Die Kunst der Typographie« and »The Elements of Typographic Style«, resp.). I don't have any other books on typography so I can't be sure but it seems this is not a typographical rule at all... –  cgnieder Mar 9 '13 at 16:07
@cgnieder I didn't write a typographical rule, I wrote view of point. A typograph has to deal with the given text, the author defines where he wants a heading. In chapter 5 (Headings) of Lesetypografie (Willberg, Forsmann) you will find an example with Heading and following subheading, explicitly said to be bad example (page 182, see inner marginal text). –  Kurt Mar 9 '13 at 17:19
@Toscho The algebraic structure in your given example is okay, but I see not your point. There is no problem to write after 2. We now will have a look on quadratic equations, because ..., differing to cubic equations (reason) and ... That is much more friendlier to read in my opinion ... –  Kurt Mar 9 '13 at 17:24

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.