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 ruleTwo-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
\newpageCustom 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 classBuilt-in page styles (no fancyhdr needed)
| \pagestyle | Effect |
|---|---|
| empty | No header/footer |
| plain | Page number in center footer (default) |
| headings | Auto chapter/section in header (book class) |
| myheadings | Manual 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\thispagestylefor one-offs. - Header on first page of chapters. book class uses plain style for chapter starts. Override with
\fancypagestyle{plain}{...}.
#set page(
header: [#text(size: 9pt)[Your Paper Title]],
footer: [#align(center)[#counter(page).display()]],
)Try TypeTeX free Frequently Asked Questions
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.
\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.
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.
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.
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).
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}{}}.
\renewcommand{\headrulewidth}{0pt} removes the header rule. \renewcommand{\footrulewidth}{0pt} removes the footer rule. To set a custom width: \renewcommand{\headrulewidth}{0.4pt}.
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.
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.