5

I am trying to remove page numbers that appear by default in footer of Table of Contents. I was able to do this for one page long Table of Contents like this one:

\documentclass[final]{book}
\pagestyle{plain}

\begin{document}

\tableofcontents
\thispagestyle{empty}

\chapter{Chapter 1}
\chapter{Chapter 2}
\chapter{Chapter 3}
\chapter{Chapter 4}

\end{document}

However, for long Table of Contents take 2 or more pages \thispagestyle{empty} only removes page number in footer from last page of Table of Contents, but all other pages have this number:

\documentclass[final]{book}
\pagestyle{plain}

\begin{document}

\tableofcontents
\thispagestyle{empty}

\chapter{Chapter 1}
\chapter{Chapter 2}
\chapter{Chapter 3}
\chapter{Chapter 4}
\chapter{Chapter 5}
\chapter{Chapter 6}
\chapter{Chapter 7}
\chapter{Chapter 8}
\chapter{Chapter 9}
\chapter{Chapter 10}
\chapter{Chapter 11}
\chapter{Chapter 12}
\chapter{Chapter 13}
\chapter{Chapter 14}
\chapter{Chapter 15}
\chapter{Chapter 16}
\chapter{Chapter 17}
\chapter{Chapter 18}
\chapter{Chapter 19}
\chapter{Chapter 20}
\chapter{Chapter 21}
\chapter{Chapter 22}
\chapter{Chapter 23}
\chapter{Chapter 24}
\chapter{Chapter 25}
\chapter{Chapter 26}
\chapter{Chapter 27}
\chapter{Chapter 28}
\chapter{Chapter 29}
\chapter{Chapter 30}
\chapter{Chapter 31}
\chapter{Chapter 32}
\chapter{Chapter 33}
\chapter{Chapter 34}
\chapter{Chapter 35}
\chapter{Chapter 36}
\chapter{Chapter 37}
\chapter{Chapter 38}
\chapter{Chapter 39}
\chapter{Chapter 40}
\chapter{Chapter 41}
\chapter{Chapter 42}
\chapter{Chapter 43}
\chapter{Chapter 44}
\chapter{Chapter 45}
\chapter{Chapter 46}
\chapter{Chapter 47}
\chapter{Chapter 48}
\chapter{Chapter 49}
\chapter{Chapter 50}
\chapter{Chapter 51}
\chapter{Chapter 52}
\chapter{Chapter 53}
\chapter{Chapter 54}
\chapter{Chapter 55}
\chapter{Chapter 56}
\chapter{Chapter 57}
\chapter{Chapter 58}
\chapter{Chapter 59}
\chapter{Chapter 60}
\chapter{Chapter 61}
\chapter{Chapter 62}

\end{document}

I have discovered that I can use \addtocontents{toc}{\protect\thispagestyle{empty}} before \chapter entry to remove footer from page on which given chapter will appear in Table of Contents. However, it requires me to either add \addtocontents{toc}{\protect\thispagestyle{empty}} before each \chapter command or at least do it manually for one chapter on each page of Table of Contents.

Is there any more straightforward way to remove footers from Table of Contents no matter how long Table of Content is?

12

As you stated, the \thispagestyle{...} command only affects the current page, so it will not help for a multi-page table of contents, except, as you do in your solution, if you ensure that it's called at least once on each page.

To momentarily change the page footer over several pages, you can use \pagestyle{...}. So the first naive thing to try is:

\pagestyle{empty}
\tableofcontents
\clearpage
\pagestyle{plain}

note the \clearpage command, so that the following \pagestyle command only takes effect on the following page and not on the last page of the table of contents.

However, there is a catch: \tableofcontents internally calls \chapter*{...}, which itself calls \thispagestyle{plain} (see book.cls source). So the first page will still have the "plain" footer style. To hack around that, I don't have a more elegant solution than to momentarily disable the \thispagestyle command itself; the total code block is then:

\pagestyle{empty}
{
  \renewcommand{\thispagestyle}[1]{}
  \tableofcontents
}
\clearpage
\pagestyle{plain}

Note the pair of braces, meant to restore the macro \thispagestyle to its original meaning after the block.

  • Is it possible to put \pagestyle{empty} inside of the brackets, so you don't have to set it back to plain afterwards? – fidekild Aug 28 '18 at 14:35
1

To avoid unnecessary typing you can define custom macro to add \addtocontents{toc}{\protect\thispagestyle{empty}} to each Table of Contents entry. It shouldn't influence document compilation time, but you will need to define similar macro for each section command that you use like \section and \subsection.

\documentclass[final]{book}
\pagestyle{plain}

\def \mychapter#1{
\chapter{#1}
\addtocontents{toc}{\protect\thispagestyle{empty}}
}


\begin{document}

\tableofcontents
\thispagestyle{empty}

\mychapter{Chapter 1}
\mychapter{Chapter 2}
\mychapter{Chapter 3}
\mychapter{Chapter 4}
\mychapter{Chapter 5}
\mychapter{Chapter 6}
\mychapter{Chapter 7}
\mychapter{Chapter 8}
\mychapter{Chapter 9}
\mychapter{Chapter 10}
\mychapter{Chapter 11}
\mychapter{Chapter 12}
\mychapter{Chapter 13}
\mychapter{Chapter 14}
\mychapter{Chapter 15}
\mychapter{Chapter 16}
\mychapter{Chapter 17}
\mychapter{Chapter 18}
\mychapter{Chapter 19}
\mychapter{Chapter 20}
\mychapter{Chapter 21}
\mychapter{Chapter 22}
\mychapter{Chapter 23}
\mychapter{Chapter 24}
\mychapter{Chapter 25}
\mychapter{Chapter 26}
\mychapter{Chapter 27}
\mychapter{Chapter 28}
\mychapter{Chapter 29}
\mychapter{Chapter 30}
\mychapter{Chapter 31}
\mychapter{Chapter 32}
\mychapter{Chapter 33}
\mychapter{Chapter 34}
\mychapter{Chapter 35}
\mychapter{Chapter 36}
\mychapter{Chapter 37}
\mychapter{Chapter 38}
\mychapter{Chapter 39}
\mychapter{Chapter 40}
\mychapter{Chapter 41}
\mychapter{Chapter 42}
\mychapter{Chapter 43}
\mychapter{Chapter 44}
\mychapter{Chapter 45}
\mychapter{Chapter 46}
\mychapter{Chapter 47}
\mychapter{Chapter 48}
\mychapter{Chapter 49}
\mychapter{Chapter 50}
\mychapter{Chapter 51}
\mychapter{Chapter 52}
\mychapter{Chapter 53}
\mychapter{Chapter 54}
\mychapter{Chapter 55}
\mychapter{Chapter 56}
\mychapter{Chapter 57}
\mychapter{Chapter 58}
\mychapter{Chapter 59}
\mychapter{Chapter 60}
\mychapter{Chapter 61}
\mychapter{Chapter 62}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.