[Tex/LaTex] book table of contents: avoid page breaks after parts

page-breakingtable of contents

I have a book with three parts, each introduced with \part{}, and using custom part pages that add a graphic to the Part page. e.g.,

\part[Exploratory and Hypothesis-testing Methods]%
 {Exploratory and Hypothesis-testing Methods\\[4ex]
 \includegraphics[width=\textwidth]{front/fig/partmap2}
}

In the table of contents, I get an extremely bad break that leaves Part II on a single line at the end of a page. How can I avoid this?

enter image description here

I can't see any easy way to prepare a MWE example for this but can provide more details if this would be helpful.

Note added in edit: This book uses the publisher-supplied class file, krantz.cls rather than book.cls. The relevant section of code for doing the TOC entries is:

\def\draw@part#1#2{%
  \addpenalty{-\@highpenalty}%
  \vskip1em plus\p@
  \@tempdima1.5em
  \begingroup
    \parindent\z@\rightskip\@pnumwidth
    \parfillskip-\rightskip
    \bfseries
    \leavevmode
    \advance\leftskip\@tempdima
    \hskip-\leftskip
    {#1\hfil}\nobreak
      \if@pdf
      \else
        \hfil\nobreak\hb@xt@\@pnumwidth{\hss #2}%
\fi
    \par
    \penalty\@highpenalty\endgroup}

\let\toc@draw\relax
%
\def\l@part#1#2{% 
\toc@draw
 \gdef\toc@draw{\draw@part{\large #1}{\large #2}}}

Best Answer

The table of contents of any document usually confirms Murphy's law: if something can go wrong, it will. Your case is exemplary!

The first rule to keep in mind is don't panic! (And remember to carry a towel with you.)

Whether the table of contents has bad breaks should not be a concern until the document is in its final form and we have decided pretty much all about typographic questions: insertion or removal of material can (and will, according to Murphy's law) change any of the clever adjustments we made for pushing a title from the second page of the table of contents to the first or conversely.

So, suppose we are at the final stage and we look at the table of contents. Oh, dear! The title of a part sits at the bottom of the first page and the relative contents is listed at the top of the second page!

  1. Relax and rejoice! Our document is finished and just need some icing.

  2. Go to the point where the \part command is issued and type, just before it,

    %%% Down with Murphy's law
    \addtocontents{toc}{\protect\pagebreak}
    %%% :-)
    
    \part[Exploratory and Hypothesis-testing Methods]%
     {Exploratory and Hypothesis-testing Methods\\[4ex]
      \includegraphics[width=\textwidth]{front/fig/partmap2}% <--- don't forget this %
     }
    
  3. Run LaTeX twice.

  4. Relax again! Our part title is on its way to the second page!

Instead of \pagebreak you could use \newpage; the difference is that with the former command TeX will try filling up the page, whereas with the latter it will truncate it. Take your pick.

Adding a distinctive series of comments surrounding these typographical adjustments will make it easier to find them when you'll be preparing the second edition of your beautiful book. The relentless Murphy's law will strike again, making most of the adjustments we made for the first edition obsolete, so having an easy way for finding them will help in removing them and add the ones we need.

Related Question