Similar questions have been asked—and answered—a number of times (e.g. here, here, and here), but all the answers seem to have the following bug: if the final page of the table of contents (TOC) has just a single item, then the required heading does not appear.

For example, the solution given here uses the atbegshi package. The minimal working example (MWE) that follows implements this solution, and it will indeed do what it is supposed to, because there will turn out to be more than one item on the final page of the TOC:

\documentclass[letterpaper]{report}
\usepackage{tocloft}

\usepackage{atbegshi}% http://ctan.org/pkg/atbegshi
\makeatletter
\bfseries% Font selection
\hspace*{\cftchapindent}% Chapter indent
\hfill%
\hfill%
}}
\AtBeginDocument{\renewcommand{\tableofcontents}{%
\begingroup%
\parindent\z@\parskip\cftparskip%
\@starttoc{toc}%
\endgroup%
}}
\newcommand{\AtBeginShipoutClear}{\gdef\AtBegShi@Hook{}}
\makeatother

\begin{document}
\tableofcontents
\AtBeginShipoutClear

\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\end{document}


Here is the output right at the page break, featuring the desired heading "Chapter no Contents Page" at the beginning of the second page of TOC:

But now just comment out the last \chapter{Something} in the code above; the result will be this:

The heading (i.e. the "Chapter no Contents Page" line) has disappeared!

The same problem occurs with the solution that uses the afterpage package (like here); and it also happens if one hacks the \output routine directly, like in this latex class.

Any ideas how to fix this?

• Off-topic: The document class option 24pt has no effect and may (should?) be omitted. On the other hand, one should probably provide the document class option letterpaper explicitly. This is important for readers whose default paper size is a4paper. – Mico Feb 25 '18 at 5:47
• Thanks for these suggestions; I've now implemented them. – Rettre Feb 25 '18 at 5:52
• Have you checked with the guideline people that you really need to input that on every page? Usually, those are meta content in an example file to say: title left, page number on the right. – Johannes_B Feb 25 '18 at 12:33
• @johannes-b First of all, the example of a TOC given in the relevant guidelines definitely has two pages, and on the second page there is the "Chapter" - "Page" heading. Second, even if it turns out the editors are forgiving about this, at this point I am also simply curious to find out how to do it! – Rettre Feb 25 '18 at 12:40

Adding \leavevmode to \AtBeginShipoutClear, forcing us back in to horizontal mode, fixes the problem:

\documentclass[letterpaper]{report}
\usepackage{tocloft}

\usepackage{atbegshi}% http://ctan.org/pkg/atbegshi
\makeatletter
\bfseries% Font selection
\hspace*{\cftchapindent}% Chapter indent
\hfill%
\hfill%
}}
\AtBeginDocument{\renewcommand{\tableofcontents}{%
\begingroup%
\parindent\z@\parskip\cftparskip%
\@starttoc{toc}%
\endgroup%
}}
\newcommand{\AtBeginShipoutClear}{\leavevmode\gdef\AtBegShi@Hook{}}
\makeatother

\begin{document}
\tableofcontents
\AtBeginShipoutClear

\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
\chapter{Something}
%\chapter{Something}
\end{document}