Skip to content
EasyLaTeXDocs

Headers, Footers, and Page Numbers

Page styles control page numbers. Use fancyhdr for custom headers and footers: clear the defaults first, then explicitly set text and page-number positions so they do not conflict with the class defaults.

EasyLaTeX compiler setting: pdfLaTeX; load fancyhdr. Thesis and publisher templates often provide their own header/footer commands; prefer those interfaces when available.

Choosing a Page Style

Common built-in styles include plain, empty, and headings:

latex
\pagestyle{plain} % Usually only the page number
\thispagestyle{empty} % No header or footer on this page

\pagestyle affects subsequent pages, while \thispagestyle affects only the current page. Covers, title pages, and some chapter-opening pages may need a separate style.

Basic Headers and Footers

Load the package, enable fancy, and clear existing definitions:

latex
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{Project Name}
\fancyhead[R]{\leftmark}
\fancyfoot[C]{\thepage}

\thepage prints the current page number. \leftmark normally contains a chapter or section heading; its precise content depends on the class.

Odd and Even Pages

For two-sided books or theses, positions such as LE and RO distinguish even and odd pages:

latex
\fancyhead[LE]{\thepage}
\fancyhead[RO]{\thepage}
\fancyhead[LO]{\rightmark}
\fancyhead[RE]{\leftmark}

L/R mean left/right; E/O mean even/odd. These distinctions matter only when two-sided layout is enabled.

Special Pages

\maketitle and chapter-opening pages often select plain automatically. Redefine that style if it should match the rest:

latex
\fancypagestyle{plain}{
  \fancyhf{}
  \fancyfoot[C]{\thepage}
  \renewcommand{\headrulewidth}{0pt}
}

This is more reliable than adding \thispagestyle manually after every chapter.

Header Height

Tall header text can trigger \headheight is too small. Follow the warning's recommendation or provide sufficient height:

latex
\setlength{\headheight}{14pt}

Do not ignore this warning: insufficient height can cause overlap or incorrect text-area calculations.

Common Problems

Page Numbers Disappear

Check for the empty style, or whether you forgot to restore \fancyfoot[C]{\thepage} after \fancyhf{}.

Chapter-Opening Pages Look Different

Many classes use plain on chapter-opening pages. Redefine plain or follow the template's chapter-style instructions.

Header Text Is Too Long

Provide a short running heading or use the template's heading commands. Do not force a full long title into a narrow header.

Complete Example

latex
\documentclass[a4paper,12pt]{article}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{Experiment Report}
\fancyhead[R]{\leftmark}
\fancyfoot[C]{\thepage}
\setlength{\headheight}{14pt}

\begin{document}
\tableofcontents
\section{Experimental Method}
This body text has a header, footer, and page number.
\newpage
\section{Experimental Results}
The second page keeps the same page style.
\end{document}
Headers, Footers, and Page Numbers | EasyLaTeX | EasyLaTeX