[Tex/LaTex] Insert footer on chapter page but NOT header

chaptersfancyhdrheader-footer

this may or may not seem to be a weird thing to want, but I would like to have a customized header on all my pages, except the first one of each chapter, ToC, ….. Furthermore, I would like to have a footer in form of a simple line above the page number on each and every page, even on the first page of a chapter, ToC, …

Well, me being new to LaTeX, I was thinking it could work if I insert the \fancypagestyle{plain} command after the header, so it might not apply for the header but for the footer. Well, that did not work.

Does anyone know how to do that? Is it even possible?

Thank you so much for any advice in advance!

\documentclass[10pt,a4paper, twoside]{report}
\usepackage[latin1]{inputenc}
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\pagestyle{fancy}

\begin{document}
\lhead[Contents]{\includegraphics[height=22pt]{Figures/WHM.eps}}
\rhead[{\includegraphics[height=22pt]{Figures/WHM.eps}}]{Contents}
\fancypagestyle{plain}{
\renewcommand{\footrulewidth}{0.4pt}}
\tableofcontents
\end{document}

Best Answer

I am not entirely sure that I understand what you want but the code below:

  • has a page footer on EVERY page with a line and the page number on the right-hand side
  • has your page headers except on the "first" pages

Rather than using fancyhdr etc I define the page headers and footers directly. When you type \pagestyle{mine} what happens is that latex executes the command \ps@mine, if it exists. The actual page headers and footers are stored in \@oddhead, \@evenhead, \@oddfoot and \@evenfoot so you just need to set these appropriately. There is also a \ps@empty command for clearing all of the current page headers and footers.

Anyway, this is what I have done:

\documentclass[10pt,a4paper,twoside]{report}
\usepackage{mwe}
\usepackage{tcolorbox}
\usepackage[foot=4em]{geometry}% need to make the footer bigger

\makeatletter
\def\my@foot{\hbox to \textwidth{\rlap{\rule[2ex]{\textwidth}{0.4pt}}\hfill\thepage}}
\def\ps@mine{\ps@empty% clear all current headings and footings
    \let\@oddfoot\my@foot\let\@evenfoot\my@foot
    \def\@oddhead{Contents\hfill\includegraphics[height=22pt]{example-image-a}}
    \def\@evenhead{\includegraphics[height=22pt]{example-image-a}\hfill Contents}
}
\def\ps@plain{% this seems to be the "first" page for report.cls
    \ps@empty\let\@oddfoot\my@foot\let\@evenfoot\my@foot
}
\makeatother
\pagestyle{mine}

\begin{document}
  \tableofcontents
  \section{A}\lipsum \section{B}\lipsum \section{C}\lipsum \section{D}\lipsum
\end{document}

Perhaps the most painful part of this game is working out which pagestyle controls the first pages of chapters etc. For report.cls this seems to be \ps@plain, so I have changed it in order to get your line in the footer on the "first" pages as well. (For amsart and friends I think it is \ps@firstpage...).

If this isn't quite what you want then please explain clearly what the problems are and I will try and fine-tune.