2

(edit) Added MWE at the end of the question.

Maybe it has something to do with redefining \thepage? If so, I don't know how to make sure otherwise that all pages other than ToC, \chapter and \part are in the new fancyhrd style.


I am trying to get rid of the fancyhdr header (including the page number in my definition) for my table of content, which is 3 pages long.

I've already tried multiple related answers, but none of them seem to work in my case. For example, I tried:

\begingroup
\makeatletter
\let\ps@fancy\ps@emptystyle
\tableofcontents
\clearpage
\endgroup

suggested here, but it doesn't seem to do anything.

I also tried:

\tableofcontents
\thispagestyle{empty}
\addtocontents{toc}{\protect\thispagestyle{empty}} 

suggested here, which works in removing the fancyhdr header from page 1 and 3 of the ToC, but not the second.

Any idea what else can I try to get this working?


\documentclass[11pt, a4paper, final]{report}

\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{blindtext}

\usepackage{hyperref}
\hypersetup{hidelinks}
\usepackage[capitalise,noabbrev,nameinlink]{cleveref}

\usepackage{fancyhdr} 

\pagestyle{fancy}
\fancyhead[R]{\thepage}
\fancyhead[L]{\textit{\nouppercase{\leftmark}}} 
\fancyfoot{} 

\fancypagestyle{plain}{ 
    \fancyhf{}
    \fancyhead[R]{\thepage}
    \fancyfoot{}}

\begin{document}

\tableofcontents
\thispagestyle{empty}
\addtocontents{toc}{\protect\thispagestyle{empty}}

\setcounter{page}{0}

\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument

\end{document}
6
  • Ans why not \pagestyle{empty} just before \tableofcontents, then\pagestyle{fancy}?
    – Bernard
    Jun 17, 2017 at 21:48
  • @Bernard: At least for book.cls \tableofcontents uses \chapter*{\contentsname}, meaning \thispagestyle{plain} is used right at the start of that comment, I fear \pagestyle{empty} would have no effect there! But as the document class is not known here, my comment is guessing only and you may be right
    – user31729
    Jun 17, 2017 at 22:42
  • @Christian Hupfer: That's why I didn't post any answer.
    – Bernard
    Jun 17, 2017 at 22:45
  • @Bernard: Nor will I do...
    – user31729
    Jun 17, 2017 at 22:45
  • 1
    Please post a compilable document that has this issue.
    – user31729
    Jun 17, 2017 at 22:46

1 Answer 1

1

If you can load package tocbasic, then you can use

\usepackage{tocbasic}
\addtotoclist[report.cls]{toc}
\renewcommand*{\tableofcontents}{\listoftoc[{\contentsname}]{toc}}% ToC under control of tocbasic
\AfterTOCHead[toc]{\thispagestyle{empty}\pagestyle{empty}}
\AfterStartingTOC[toc]{\clearpage}

enter image description here

Note that tocbasic can not be used together with tocloft.

Code:

\documentclass[11pt, a4paper, final]{report}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage[capitalise,noabbrev,nameinlink]{cleveref}

\usepackage{fancyhdr} 
\setlength\headheight{13.6pt}% as suggested by fancyhdr
\pagestyle{fancy}
\fancyhead[R]{\thepage}
\fancyhead[L]{\textit{\nouppercase{\leftmark}}} 
\fancyfoot{} 

\fancypagestyle{plain}{ 
    \fancyhf{}
    \fancyhead[R]{\thepage}
    \fancyfoot{}}

\usepackage{tocbasic}
\addtotoclist[report.cls]{toc}
\renewcommand*{\tableofcontents}{\listoftoc[{\contentsname}]{toc}}% ToC under control of tocbasic
\AfterTOCHead[toc]{\thispagestyle{empty}\pagestyle{empty}}
\AfterStartingTOC[toc]{\clearpage}

\usepackage{hyperref}
\hypersetup{hidelinks}
\begin{document}
\pagenumbering{roman}% use a different numbering scheme to avoide the same identifier problem
\tableofcontents

\cleardoublepage
\pagenumbering{arabic}
\Blinddocument\Blinddocument\Blinddocument\Blinddocument\Blinddocument
\Blinddocument\Blinddocument\Blinddocument\Blinddocument\Blinddocument
\Blinddocument\Blinddocument\Blinddocument\Blinddocument\Blinddocument
\Blinddocument\Blinddocument\Blinddocument\Blinddocument\Blinddocument
\end{document}
3
  • This seems to work. Just to be sure: I don't need to use the previous \thispagestyle{empty} and \addtocontents{toc}{\protect\thispagestyle{empty}} anymore, right? Jun 18, 2017 at 11:31
  • Yes, you do not need these additional lines anymore. The suggestion uses hooks provided by tocbasic.
    – esdd
    Jun 18, 2017 at 12:05
  • Thanks! (also for fixing the warning issues). Will mark as answered. Jun 18, 2017 at 12:31

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.