In a recent comment, I was asked if there is a way to carry over the table of contents heading in the report document class. In other words, reproduce the heading on every page of the table of contents.
The atbegshi package offers a solution. The package provides a hook, which allows execution of macros at the beginning of every page. It is similar to the everyshi package, which allows execution of code at the end of every page.
Carry over table of contents heading
To carry over the TOC heading, we load the atbegshi
package in the preamble:
\usepackage{atbegshi}
Next, we use the hook provided by the package to execute code at the beginning of every page.
\AtBeginShipout{...}
Since we only want to reproduce the heading for pages of the contents and not throughout the document, we have to use a trick. We define the MyShipoutHook
macro to add the heading. To change or clear the content produced at the beginning of every page, we simply change the macro.
\newcommand\MyShipoutHook{\chapter*{\contentsname}} \AtBeginShipout{\MyshipoutHook} \tableofcontents \renewcommand\MyShipoutHook{} \clearpage
Conveniently, this does not affect the first page of a chapter, which already has a heading.
List of figures and list of tables
Similarly, to carry over headings for the list of figures and the list of tables, we adapt the \MyShipoutHook
macro accordingly:
\AtBeginShipout{\MyshipoutHook} \tableofcontents \clearpage \renewcommand\MyShipoutHook{\chapter*{\listfigurename}} \listoffigures \clearpage \renewcommand\MyShipoutHook{\chapter*{\listtablename}} \listoftables \clearpage \renewcommand\MyShipoutHook{}
Again, by leaving the macro empty in the last line, no headings will be produced for subsequent pages.
Limitations
The solution presented here works well with the report
document class, when the default options are used (openany
, oneside
). However, with openright
and twoside
options active, the heading gets printed multiple times and extra blank pages are added for obvious reasons.
A possible solution might be to manually produce the heading instead of using the chapter
command. To make the title look the same, I copied the relevant code from the report
class definition.
\newcommand\MyShipoutHook{\Huge\bfseries\contentsname\par\vskip 40pt}
Throughout the examples, I only considered the starred version of \chapter
. However, you might want to do something similar with non-starred/numbered chapters. In this case, things might be quite complicated, depending on the requirements. If you have a specific problem, please use the form below to describe it and provide a minimal working example.
Finally, I did not test the code for any document class other than report
. But I would assume that for article
it should work similarly.
Complete code example
\documentclass[11pt]{report} \usepackage{atbegshi,blindtext,pgffor} \newcommand\MyShipoutHook{\chapter*{\contentsname}} \begin{document} \AtBeginShipout{\MyShipoutHook} \tableofcontents \renewcommand\MyShipoutHook{} \clearpage \foreach \n in {0,...,22}{\chapter{Some chapter}\Blindtext} \end{document}