Tx · LaTeX & TikZ

Why Is fancyhdr Not Working on Every Page?

Published By the 9to5Science editorial team

At a glance

  1. 1. Set the main style

    Use \pagestyle{fancy} to apply fancyhdr to pages throughout the document.

  2. 2. Check plain pages

    Redefine the plain style too; chapter-opening pages in book and report commonly use it.

  3. 3. Look for overrides

    Search for \thispagestyle, title-page commands, and environments that assign another page style.

  4. 4. Check layout warnings

    Set a sufficient headheight and inspect the LaTeX log for fancyhdr warnings.

Advertisement

The fancyhdr package defines header and footer layouts through LaTeX page styles. If the layout appears on ordinary pages but not every page, the missing pages are often using a different style—especially the plain style used on chapter-opening pages in book and report documents.

Set the main style with \pagestyle{fancy} and define any other styles the document uses. The complete example below applies the same header and footer to both fancy and plain pages in a two-sided book.

A working example for every page

\documentclass[twoside]{book}
\usepackage{fancyhdr}

\setlength{\headheight}{15pt}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[CE,CO]{My document}
\fancyfoot[LE,RO]{\thepage}

\fancypagestyle{plain}{%
  \fancyhf{}
  \fancyhead[CE,CO]{My document}
  \fancyfoot[LE,RO]{\thepage}
}

\begin{document}

\chapter{First chapter}
This is a chapter-opening page. It uses the plain page style.

\newpage
This page uses the main fancy page style.

\end{document}

The CE,CO positions put the header in the center on even and odd pages. LE,RO put the page number at the outer edge of even and odd pages. The \fancypagestyle{plain}{...} block sets the chapter-opening style; without it, those pages may have a page number but not your custom header.

The \headheight length reserves space for the header. If your header is taller, increase this value to address the warning in the LaTeX log. The example uses a short header that normally fits in 15 points.

Why some pages use another style

A page style determines what appears in the header and footer. \pagestyle{fancy} selects the fancy style for the document, but a class, command, or environment can select another style on particular pages.

Common cases include:

  • Chapter openings: book and report commonly use plain on the page where a chapter starts.
  • A one-page change: \thispagestyle{empty} or \thispagestyle{plain} affects only the current page. Search for these commands if just one page differs.
  • Title pages: title commands or a titlepage environment may choose a separate style. If the title page should have a header, check which style it selects and set that style too.
  • Custom environments or commands: a package or template may change page styles for special pages, such as a table of contents or a landscape page.

To find the cause, search the source for \thispagestyle, \pagestyle, \fancypagestyle, and empty. Check the document class and template as well: a command in a class or package may set a style even when it is not written in your main .tex file.

Common mistakes

Defining fancy but not plain. This is the most common cause in documents with chapters. Redefine plain as shown above if those pages should match.

Confusing \thispagestyle with \pagestyle. \thispagestyle{fancy} changes only the current page. \pagestyle{fancy} sets the style for the document, though later commands can still override it.

Assuming a blank header means the style is not active. A header field can be empty because its content, such as a chapter or section mark, has not been set on that page. Try a fixed label temporarily to test whether the style is applied.

Ignoring layout warnings. If the header is too tall, fancyhdr may warn that \headheight is too small. Increase it to the value needed by your actual header; otherwise the header can overlap the text area or affect page layout.

Using odd/even positions in a one-sided document. In a two-sided layout, LE and RO refer to the outer positions on even and odd pages. If you use oneside, or want a centered item on every page, choose positions that fit that layout, such as C for a centered field.

References

  1. The fancyhdr and extramarks package — CTAN

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.