# Fancyhdr does not apply same header/footer on chapter and non-chapter pages

I have a problem with the fancy package: I use the report documentclass and I have a chapter, a lot of text and then a new page starting with a section (or the next page has no chapter starting on that particular page).

The problem be, that what I defined for my header and footer is NOT on the chapter-page but only on the non-chapter page. How come? What did I miss?

Minimal example:

\documentclass[]{report}

\usepackage{lastpage}
\usepackage{fancyhdr} % for use of \pageref{LastPage}

\fancypagestyle{IHA-fancy-style}{%
\fancyfoot[C]{\thepage of \pageref{LastPage}} %Custom footer
\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}


Take notice: No line on page 2 at the bottom - a line on page 3 at the bottom.

Any clues?

-
Oh - So how do I get around this? Should I redefine \chapter? –  Limro Jun 2 '13 at 20:41
@kahen - Actually, \chapter issues \thispagestyle{plain}. –  Mico Jun 2 '13 at 20:59
@Mico - where do you get this? Perhaps I can pick up how to override it with my own style... –  Limro Jun 2 '13 at 21:01
@Limro - I've posted an answer that shows how you might modify the page style of the first page of chapters. –  Mico Jun 2 '13 at 21:09
In general one doesn't want headers in a chapter starting page: there's no need for them; moreover this will give a more distinctive look to those pages. In particular a rule above the chapter title doesn't look very nice. –  egreg Jun 2 '13 at 21:20

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}{%
\fancyfoot[C]{\thepage\ of \pageref{LastPage}}% Custom footer
\renewcommand{\footrulewidth}{0.4pt}% Line at the footer visible
}

% Redefine the plain page style
\fancypagestyle{plain}{%
\fancyhf{}%
\fancyfoot[C]{\thepage\ of \pageref{LastPage}}%
\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}

-

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 ...

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.7955206036567688, "perplexity": 4731.244613183417}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-52/segments/1418802771384.149/warc/CC-MAIN-20141217075251-00154-ip-10-231-17-201.ec2.internal.warc.gz"}