Headers & Footers in LaTeX with fancyhdr
To customize headers and footers in LaTeX, load the fancyhdr package, set the page style to fancy, and define left/center/right content for each. Full setup inside.
To customize headers and footers in LaTeX, load fancyhdr, switch the page style to fancy, and define left, center, and right content for the header and footer. It replaces the plain page number with running heads, chapter titles, dates, or logos. Here's the complete setup, including the chapter-page and rule gotchas.
1. Basic fancyhdr setup
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear all defaults first
\fancyhead[L]{\leftmark} % chapter title, left header
\fancyhead[R]{\thepage} % page number, right header
\fancyfoot[C]{Confidential Draft}
\fancyhf{} wipes existing content so nothing lingers. [L], [C], [R] are left, center, right.
2. Running heads from the document
| Macro | Contains |
|---|---|
| \thepage | Current page number |
| \leftmark | Current chapter title |
| \rightmark | Current section title |
| \today | Compilation date |
These update automatically as the reader moves through the document.
3. Two-sided documents
\fancyhead[LE,RO]{\thepage} % page no. outer corner
\fancyhead[RE]{\leftmark} % chapter on even (left) pages
\fancyhead[LO]{\rightmark} % section on odd (right) pages
E/O mean even/odd pages — essential for a printed, two-sided thesis.
4. Fix chapter-opening pages
Chapter-start pages use the plain style (no fancy header). Restyle it:
\fancypagestyle{plain}{%
\fancyhf{}%
\fancyfoot[C]{\thepage}%
}
5. Control the rules
\renewcommand{\headrulewidth}{0.4pt} % line under header
\renewcommand{\footrulewidth}{0pt} % no line above footer
Set \headrulewidth to 0pt to remove the header line entirely. Headers pair with margins and page layout for a polished document; many journal classes set their own, so override only for custom layouts.
→ Design headers and footers with live preview in LetX.
Written by Shihab Shahriar Antor — AI Engineer & Founder of Shahriar Labs, maker of LetX.
Frequently Asked Questions
How do I put the page number in the footer and the chapter title in the header?
With fancyhdr, set \pagestyle{fancy}, then \fancyfoot[C]{\thepage} puts the page number centered in the footer, and \fancyhead[L]{\leftmark} puts the current chapter title in the left header. \leftmark holds the chapter mark and \rightmark the section mark, both updated automatically as the document progresses. Clear the defaults first with \fancyhf{} so old content doesn't linger.
Why is the header missing on the first page of a chapter?
LaTeX applies the plain page style to chapter-opening pages, which shows only a centered page number and no fancy header. To restyle those pages, redefine the plain style: \fancypagestyle{plain}{\fancyhf{}\fancyfoot[C]{\thepage}}. This is expected behavior, not a bug — the report and book classes deliberately suppress the running head where a chapter title already appears at the top of the page.
How do I remove the horizontal rule under the header?
Set its thickness to zero: \renewcommand{\headrulewidth}{0pt} removes the line under the header, and \renewcommand{\footrulewidth}{0pt} removes the one above the footer (the footer rule is 0 by default). To make the header rule thicker instead, set it to a positive length like 1pt. These commands go in the preamble after loading fancyhdr.