Fancyhdr does not apply same header/footer on chapter and non-chapter pages
For the report
document class, the command \chapter
is defined in the file report.cls
, starting on line 339 or so. Contained in the definition of the \chapter
macro is the instruction \thispagestyle{plain}
, instructing LaTeX to set the chapter's first page in the so-called "plain" style.
To switch the page style of the first page of a chapter from "plain" to "fancy", you could load the etoolbox
package and patch the definition of the \chapter
macro:
\documentclass{report}
% other preamble stuff...
\usepackage{etoolbox}
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}
% rest of document ...
You can redefine the plain
style that's issued by \chapter
. Here's how you can do; I'd recommend not having headings in the chapter starting pages, nor the upper rule.
\documentclass[twoside]{report}
\usepackage{lastpage}
\usepackage{fancyhdr} % for use of \pageref{LastPage}
\fancypagestyle{IHA-fancy-style}{%
\fancyhf{}% Clear header and footer
\fancyhead[LE,RO]{\slshape \rightmark}
\fancyhead[LO,RE]{\slshape \leftmark}
\fancyfoot[C]{\thepage\ of \pageref{LastPage}}% Custom footer
\renewcommand{\headrulewidth}{0.4pt}% Line at the header visible
\renewcommand{\footrulewidth}{0.4pt}% Line at the footer visible
}
% Redefine the plain page style
\fancypagestyle{plain}{%
\fancyhf{}%
\fancyfoot[C]{\thepage\ of \pageref{LastPage}}%
\renewcommand{\headrulewidth}{0pt}% Line at the header invisible
\renewcommand{\footrulewidth}{0.4pt}% Line at the footer visible
}
\title{A short example}
\begin{document}
\maketitle
\tableofcontents
\pagestyle{IHA-fancy-style}
\chapter{A chapter}
Look at the footer
\newpage
\section{A section}
Look at the footer
\end{document}