Page Layout ⇒ Headers missing for ToC, LoF and LoT
Headers missing for ToC, LoF and LoT
I am having difficulties with a report that I am writing for work. I have been using the fancyhdr package to include headers and footers on all pages. No troubles with this whatsoever. More recently, I added the tocloft package to modify the spacing on the ToC. This seemed to be working great, but yesterday I noticed that I no longer have headers and footers on the ToC, LoF, or LoT. For the reports that I am writing, having headers and footers on these pages is absolutely necessary.
I was able to trace the problem back to a conflict between fancyhdr and tocloft. If I comment out the tocloft package definition, the headers and footers are displayed correctly. But they disappear when the tocloft package definition is active.
Any thoughts or suggestions on how to make these two packages work together?
Thanks,
Matt
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Headers missing for ToC, LoF and LoT
Probably this is not related to tocloft. The
plain
page style is the default on all chapter pages. How to redefine this style can be found in Section 7 of the fancyhdr manual.Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Headers missing for ToC, LoF and LoT
First, compile it as it currently is. The output should be two pages, the ToC and the fake report body. You'll see that the ToC does not have the header or footer, but the report body page has both the header and footer.
Next, comment out lines 22, 26-59 and compile. The spacing on the ToC gets messed up, but the header and footer are included on both pages.
Any thoughts or suggestions?
Code: Select all
%
% This is a Minimal LaTeX document
%
\documentclass[12pt]{article}
\usepackage{times}
\usepackage[top=.75in,bottom=0.75in,left=1.0in,right=1.0in]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
% Header
\lhead{}
\chead{\textbf{HEADER}}
\rhead{}
% Footer
\renewcommand{\footrulewidth}{0.4pt}
\lfoot{}
\cfoot{\textbf{FOOTER}}
\rfoot{\thepage}
\usepackage{parskip}
\usepackage{tocloft}
\usepackage[colorlinks=true, linkcolor=blue, citecolor=blue]{hyperref}
% ******************************* ToC Definition *****************************
\makeatletter
\renewcommand\l@section[2]{%
\ifnum \c@tocdepth >\z@
\addpenalty\@secpenalty
\addvspace{1.0em \@plus\p@}%
\setlength\@tempdima{4.0em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \bfseries
\advance\leftskip\@tempdima
\hskip -\leftskip
#1\nobreak\
\leaders\hbox{$\m@th\mkern \@dotsep mu\hbox{.}\mkern \@dotsep mu$}
\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\endgroup
\fi}
\renewcommand\l@subsection[2]{%
\ifnum \c@tocdepth >\@ne
\addpenalty\@subsecpenalty
\addvspace{0.5em \@plus\p@}%
\setlength\@tempdima{5.0em}%
\begingroup
\parindent \cftsubsecindent\relax\@afterindenttrue
\rightskip \@tocrmarg
\parfillskip -\rightskip
\advance\leftskip \@tempdima
\hskip -\leftskip
#1\nobreak\
\leaders\hbox{$\m@th\mkern \@dotsep mu\hbox{.}\mkern \@dotsep mu$}
\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\endgroup
\fi}
\makeatother
% ******************************* Portion Marking ****************************
\newcommand*\U{\reversemarginpar \marginpar{\flushright{\textcolor{red}{\textbf{(U)}}}}}
\renewcommand{\thesection}{\textcolor{red}{\textbf(U) \hspace{0.5em}} \arabic{section} }
\renewcommand{\contentsname}{\textcolor{red}{\textbf(U) \hspace{0.5em}} Contents}
% ******************************* Begin Document *****************************
\begin{document}
% ******************************* Table of Contents **************************
\phantomsection
\addcontentsline{toc}{section}{\textcolor{red}{(U)} \hspace{0.5em} Table of Contents}
\setcounter{page}{1}
\setcounter{tocdepth}{2}
\tableofcontents
\pagebreak
% ****************************** Fake Section ********************************
\section{Fake Section}
This \U section would be the start the body of the report.
\subsection{Fake Subsection}
This \U is a fake subsection for example purposes.
\end{document}
Headers missing for ToC, LoF and LoT
Correct. I had to uselocalghost wrote:Probably this is not related to tocloft. Theplain
page style is the default on all chapter pages.
\thispagesytle{fancy}
after my definitions for ToC, LoF, and LoT. Thanks for the help!Matt