[Tex/LaTex] Keep chapter headings and related subheadings in the same page in ToC

page-breakingtable of contents

I'm trying to finish my master's thesis and all I have left are some formatting issues. I'm trying to prevent LaTeX from breaking a chapter and its subheadings in between pages in my table of contents.

My problem is the following:

Table of Contents

... some stuff here ....

CHAPTER W
    ...
    ...

CHAPTER X
----------- Latex inserts page break here -------
<end of page>

<next page>
    chapter x subheading 1
    chapter x subheading 2

And this is what I want to happen:

Table of Contents

... some stuff here ....

CHAPTER W
    ...
    ...

<end of page>
<next page>

CHAPTER X
    chapter x subheading 1
    chapter x subheading 2

Basically, I want to make sure that the Chapter heading is not left "orphaned" in one page, while its subheadings are in another page.

What would be the simplest enforce this in LaTeX? It's only one chapter heading that's being orphaned in my ToC. I've considered using the package to adjust the title spaces, but this might be overkill. Perhaps someone may have an elegant solution. 😀

Best Answer

barbara beeton has already hinted a manual solution, namely, "put a line \addtocontents{toc}{\newpage} just before the\chapter command that causes the "orphaned" line". I'll add that while LaTeX's "core" ToC mechanism doesn't prevent "orphaned" ToC entries, there are at least two ToC-related packages that deal with this problem in an automatic way: tocloft and tocstyle (alpha version, part of KOMA-Script). The following example includes both alternatives -- uncomment the respective code lines to see the effect.

\documentclass{book}

% Alternatve A
% \usepackage{tocloft}% Moves "gnu" ToC entry to first page

% Alternative B
% \usepackage{tocstyle}\usetocstyle{standard}% Moves "bar" ToC entry to second page

\begin{document}

\tableofcontents

\chapter{foo}

\addtocontents{toc}{\vspace{31\baselineskip}}

\chapter{bar}

\section{gnu}

\end{document}
Related Question