Skip to main content
v2026.11,986 entries · CC-BY 4.0

LaTeX Header and Footer with fancyhdr: Commands and Fixes

How to set a LaTeX header and footer with fancyhdr: slot codes, rules, chapter and section marks, first-page styles and the headheight warning fix.

Written and maintained by CASRAI Editorial Board

Published · Last updated

On this page

To put running text in the header or footer of a LaTeX document, load the fancyhdr package, switch on its page style with \pagestyle{fancy}, and fill the six slots (left, centre and right, in the header and in the footer) with \fancyhead and \fancyfoot. Rule thickness, the first-page layout and chapter or section titles in the header are each controlled by a few further commands, covered below with the exact warnings the package prints when something is off.

What it is used for in research

Theses, reports and journal-style manuscripts often need a running header (chapter or section title, short title, author) and a footer (page number, document version, recipient). The package fancyhdr, maintained by Pieter van Oostrum and published on CTAN, provides that. The manual describes a page as having a left, centred and right header, the body, and a left, centred and right footer. This guide follows the fancyhdr manual, version 5.2 of 7 February 2025, and the Overleaf documentation page on headers and footers, both read on 2026-11-14.

Page numbering itself (style, restarting, roman numerals) is covered separately in page numbers in LaTeX; this page covers the header and footer content, rules and marks around it. If a header or footer lands on the wrong page, see also page breaks in LaTeX.

How to install or access it

fancyhdr is published on CTAN at ctan.org/pkg/fancyhdr, with the manual as fancyhdr.pdf in the package directory. The manual states that the package is distributed under the LaTeX Project Public License. You load it in the preamble:

\usepackage{fancyhdr}
\pagestyle{fancy}

Package options go in square brackets before the name. The manual lists nocheck, compatV3 (deprecated), twoside (two-sided headers in a one-sided document, from version 4.1), headings and myheadings.

1. Choose the slots with the place code

The commands \fancyhead[places]{field}, \fancyfoot[places]{field} and \fancyhf[places]{field} (header and footer together) take a place made of letters: E or O (even or odd page), L, C or R (left, centre, right) and H or F (header or footer). The manual counts twelve places, each written with three letters such as EOH. A coordinate you leave out means all possibilities, except that \fancyhead implies H and \fancyfoot implies F. Lowercase letters are accepted. Overleaf’s page shows the same idea with \fancyhead[RO,LE]{...} and \fancyfoot[LE,RO]{\thepage}, and the three-coordinate form \fancyhf[EHC]{...}.

Place codes at a glance

Code Meaning Example from the sources
E / O Even or odd page (needs a two-sided document) \fancyhead[RO,LE]{...}
L / C / R Left, centre or right slot \fancyfoot[C]{To: Dean A. Smith}
H / F Header or footer (implied by fancyhead and fancyfoot) \fancyhf[EHC]{...}
No letter for a coordinate All possibilities for that coordinate \fancyhead{} clears every header slot

2. Clear the defaults, then fill the slots

\fancyhf{} empties every header and footer field, the starting point Overleaf’s page uses before defining new fields. The fancyhdr manual’s first example fills them like this:

\fancyhead[L,C]{}
\fancyhead[R]{\textbf{The performance of new graduates}}
\fancyfoot[L]{From: K. Grant}
\fancyfoot[C]{To: Dean A. Smith}
\fancyfoot[R]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{2pt}

3. Set the rules

\headrulewidth is the thickness of the line under the header and \footrulewidth the thickness of the line above the footer. They are macros, so change them with \renewcommand. Overleaf states that \setlength does not work on them, and the manual notes that version 1 of the package used \setlength while the current one uses \renewcommand. Since version 4.0 the spacing around the rules is available as \headruleskip and \footruleskip. To remove a rule entirely, redefine it as empty; for a dotted rule the manual gives a replacement definition:

\renewcommand{\headrule}{}
\renewcommand{\headrule}{\vbox to 0pt{\makebox[\headwidth]{\dotfill}\vss}}

(The first line removes the header rule; the second replaces it with a dotted one. Use one or the other.)

4. Show chapter and section titles with marks

Running titles come from LaTeX marks. \markboth{left}{right} and \markright{right} set them; \leftmark holds the left argument of the last \markboth on the page and \rightmark the right argument of the first \markboth or \markright. The manual’s sixth example redefines the mark commands so that the header reads, for instance, “Chapter 2. Implementation” and “2.1. First steps”:

\renewcommand{\chaptermark}[1]{\markboth{\chaptername \thechapter. #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection. #1}}

Put these after the first \pagestyle{fancy}. Marks can come out in capitals; wrap the field in \nouppercase{...} to stop that, as in the manual’s seventh example \fancyhead[L]{\nouppercase{\rightmark}} and \fancyhead[R]{\nouppercase{\leftmark}}. The manual cautions that this also affects uppercase roman numerals.

5. Handle the first page and special pages

\thispagestyle{empty} removes all headers and footers from the current page; \thispagestyle{plain} leaves only a centred page number. The standard classes’ \maketitle issues \thispagestyle{plain}, so the title page will not show your fancy layout. Add \thispagestyle{fancy} right after \maketitle if you want it kept. For a style you reuse, the manual recommends defining your own with \fancypagestyle{name}[base]{definitions} rather than editing the built-in headings style.

A worked thesis preamble

The block below combines the manual’s mark and uppercase examples into one two-sided setup: chapter title on the left of even pages, section title on the right of odd pages, page number in the outer footer corner. It is assembled from the documented commands above; compile it in your own class (it assumes a class with chapters, such as book or report).

\documentclass[twoside]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\chaptermark}[1]{\markboth{\chaptername \thechapter. #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection. #1}}
\fancyhead[LE]{\nouppercase{\leftmark}}
\fancyhead[RO]{\nouppercase{\rightmark}}
\fancyfoot[LE,RO]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}

Note the order: \fancyhf{} comes first, then the mark redefinitions, then the slots. Redefine \chaptermark and \sectionmark after \pagestyle{fancy}, as the manual instructs. For the surrounding structure of a thesis, see thesis templates in LaTeX, and for the title page thesis title pages.

Output and how to read it

After compiling, each page should show the header text above the body and the footer text below it, with a thin line under the header when \headrulewidth is above zero. In the worked preamble, even pages carry the chapter title at the top left and odd pages the section title at the top right; the page number sits in the outer bottom corner. Because \leftmark is the left argument of the last \markboth on the page and \rightmark the right argument of the first one, check a chapter-opening page and the first page after a section change when you verify the result.

Troubleshooting

Warning: headheight is too small

The package prints: Package fancyhdr Warning: \headheight is too small (12.0pt): Make it at least 14.0pt, for example: \setlength{\headheight}{14.0pt}. You might also make \topmargin smaller: \addtolength{\topmargin}{-2.0pt}. Since version 4.0 fancyhdr no longer changes \headheight itself, so set it in the preamble, for example \setlength{\headheight}{14pt}. The text then moves 2 pt lower; the manual suggests compensating with \addtolength{\topmargin}{-2pt}. The nocheck option silences the warning but the manual discourages it. With the geometry package, Overleaf shows includehead and headheight=2cm as options.

The rule thickness does not change

You used \setlength on \headrulewidth. Use \renewcommand{\headrulewidth}{2pt} instead.

E or O places have no effect

Even and odd fields need a two-sided document. Overleaf warns that using E without twoside misbehaves; declare \documentclass[twoside]{article} (or the twoside package option for fancyhdr in a one-sided class).

The title page has the wrong header

See step 5: \maketitle sets the plain style on its page. Use \thispagestyle{fancy} after it, or \thispagestyle{empty} to remove everything. For a deliberately blank page, Overleaf shows \newpage\thispagestyle{empty} and mentions the emptypage package.

Header titles appear in capitals

If the mark text is printed in capitals, wrap the field in \nouppercase{} (step 4); the manual notes this also affects uppercase roman numerals.

Free alternatives

Option What it gives Source
fancyhdr Six header/footer slots, rules, marks, custom page styles; LaTeX Project Public License fancyhdr manual v5.2, CTAN
Built-in page styles empty, plain, headings, myheadings Fixed layouts with no package needed; empty has no header or footer, plain only a page number Overleaf, Headers and footers

FAQ

Put \thispagestyle{empty} on that page. To keep only a centred page number use \thispagestyle{plain}.

Do I need fancyhdr for a simple page number?

No: the built-in plain style gives a centred page number. See page numbers in LaTeX for position and restart options.

How do I put the chapter title in the header?

Redefine \chaptermark with \markboth and print \leftmark in a header slot (steps 4 and the worked preamble).

Sources

Data: LaTeX header and footer problems and the documented fix (fancyhdr)

Symptoms commonly met when setting a LaTeX header or footer with fancyhdr, with the cause and the command or option that the fancyhdr manual v5.2 or Overleaf documentation gives as the fix.

Period covered: 2025/2026.

LaTeX header and footer problems and the documented fix (fancyhdr)
SymptomCauseDocumented fixSource
Warning: \headheight is too small (12.0pt)fancyhdr no longer changes \headheight since v4.0\setlength{\headheight}{14pt} and \addtolength{\topmargin}{-2pt}fancyhdr manual v5.2
Rule thickness does not change\headrulewidth and \footrulewidth are macros, not lengths\renewcommand{\headrulewidth}{2pt}Overleaf; fancyhdr manual v5.2
Even/odd (E, O) fields ignoredDocument is one-sided\documentclass[twoside]{article}Overleaf
Title page shows only a page number\maketitle issues \thispagestyle{plain}\thispagestyle{fancy} after \maketitlefancyhdr manual v5.2
Header titles shown in capitalsMark text is shown in capitals\nouppercase{\leftmark}fancyhdr manual v5.2
Header rule not wantedThe rule is drawn by the \headrule macro\renewcommand{\headrule}{}fancyhdr manual v5.2

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about LaTeX Header and Footer with fancyhdr: Commands and Fixes

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →