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}
Chockalingam Sivakumar
Hi Tom,
I need to have 2″ top margin in the first page of the table of contents (2 inch vertical space before the title of TOC). How could I modify this?
tom
The geometry package should do the trick.
Chockalingam Sivakumar
Thanks for the reply!
The Contents section spans multiple pages. I just want the ‘CONTENTS’ title to have 2 inches top margin. Sorry, I am a newbie to Latex.
tom
Hi there,
My mistake, sorry. The tocloft package provides a macro to control the spacing before the contents list (see below). Specifically, I add
2in
and subtract the default top margin, using the calc package. The last number subtracts the font size. Although I’m not sure why, there seems to be an extra (text) line of vertical space by default, in addition to the top margin. With that, you should get exactly2in
of vertical space before “Contents”.Cheers, Tom.
Mary
how to repeat first row ” Figure Description Page ” at the top of each lof pages ??
Mary
I just solved it by modifying one line as
^_^
tom
Thanks for posting your solution here! Best wishes, Tom.