LaTeX Guide

LaTeX Header & Footer

Use fancyhdr. \fancyhead[L/C/R] for header positions, \fancyfoot[L/C/R] for footer. \thispagestyle{empty} to suppress on a single page.

Basic setup

\usepackage{fancyhdr}
\pagestyle{fancy}

\fancyhf{}                     % clear default header and footer
\fancyhead[L]{Your Paper Title}
\fancyhead[R]{Your Name}
\fancyfoot[C]{\thepage}        % page number in center footer

\renewcommand{\headrulewidth}{0.4pt}    % header rule
\renewcommand{\footrulewidth}{0pt}      % no footer rule

Two-sided layout (book / report)

\documentclass[twoside]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}

% Even (left) pages: chapter on left, page on right
\fancyhead[LE]{\leftmark}
\fancyhead[RE]{\thepage}

% Odd (right) pages: page on left, section on right
\fancyhead[LO]{\thepage}
\fancyhead[RO]{\rightmark}

Skip header on title page

\maketitle
\thispagestyle{empty}    % no header/footer on this page only
\newpage

Custom page styles

% Define a "plain" style with just page number in center footer
\fancypagestyle{plain}{
  \fancyhf{}
  \fancyfoot[C]{\thepage}
  \renewcommand{\headrulewidth}{0pt}
}

% Apply to chapter-opening pages
% \chapter{Title}
% \thispagestyle{plain}    % already automatic in book class

Built-in page styles (no fancyhdr needed)

\pagestyleEffect
emptyNo header/footer
plainPage number in center footer (default)
headingsAuto chapter/section in header (book class)
myheadingsManual headings via \markboth/\markright

Common mistakes

  • Forgetting \fancyhf{}. Causes duplicate page numbers from inherited defaults.
  • Headheight warnings. fancyhdr complains if \headheight is too small. Set \setlength{\headheight}{14pt} or whatever it suggests.
  • Mixing pagestyle and fancyhdr. After \pagestyle{fancy}, all subsequent pages use fancy unless you use \thispagestyle for one-offs.
  • Header on first page of chapters. book class uses plain style for chapter starts. Override with \fancypagestyle{plain}{...}.
Typst headers/footers via #set page
#set page(
  header: [#text(size: 9pt)[Your Paper Title]],
  footer: [#align(center)[#counter(page).display()]],
)
Try TypeTeX free

Frequently Asked Questions

How do I add a header or footer in LaTeX?

Load the fancyhdr package: \usepackage{fancyhdr} \pagestyle{fancy}. Then \fancyhead[L]{Left header} \fancyhead[R]{Right header} \fancyfoot[C]{\thepage} for centered page number. The L/C/R arguments specify left/center/right positions.

How do I put the page number in the footer?

\pagestyle{fancy} \fancyhf{} (clear all) \fancyfoot[C]{\thepage}. The \thepage macro prints the current page number. Use [L] or [R] for left/right alignment instead of center.

What's \fancyhf{} for?

It clears all pre-existing header/footer content. Without it, fancyhdr inherits the default plain style and you might get duplicated page numbers. Always start a fancyhdr setup with \fancyhf{} to start from a clean slate.

How do I make different headers for odd and even pages?

Pass \documentclass[twoside]{article} (or use book/report which default to twoside). Then \fancyhead[LE]{Left on Even} \fancyhead[RO]{Right on Odd}. The two-letter codes: LE=left-even, RE=right-even, LO=left-odd, RO=right-odd, CE/CO for center.

How do I suppress the header/footer on the title page?

After \maketitle add \thispagestyle{empty} to remove header/footer on that one page. \thispagestyle only affects the current page. For multiple pages: \pagestyle{empty} ... \pagestyle{fancy} (toggle when needed).

How do I add chapter or section title to the header?

Use \leftmark and \rightmark — fancyhdr's automatic markers. \fancyhead[L]{\leftmark} shows the current chapter (uppercase by default). \fancyhead[R]{\rightmark} shows the current section. Override the case: \renewcommand{\chaptermark}[1]{\markboth{Chapter \thechapter: #1}{}}.

How do I remove the horizontal rule above/below the header?

\renewcommand{\headrulewidth}{0pt} removes the header rule. \renewcommand{\footrulewidth}{0pt} removes the footer rule. To set a custom width: \renewcommand{\headrulewidth}{0.4pt}.

How do I use a custom page style only for some pages?

Define your own: \fancypagestyle{mystyle}{\fancyhf{}\fancyfoot[C]{\thepage}\renewcommand{\headrulewidth}{0pt}}. Then \pagestyle{mystyle} or \thispagestyle{mystyle} to apply. Useful for chapter-opening pages or appendices.

Why does my header overlap with the body text?

The header eats into the textheight by default. Set \setlength{\headheight}{14pt} (or whatever fancyhdr suggests in its warning). For fancier setups: \setlength{\headsep}{20pt} adds space between header and body. The geometry package can also adjust these in one place.

More LaTeX guides