Configure page numbers with fancyhdr in LaTeX.
Calling \fancyhf{} clears headers and footers completely, which wipes out the default page number. Restoring and positioning your page number requires placing \thepage into a specific header or footer slot such as \fancyfoot[C]{\thepage} or \fancyhead[RO,LE]{\thepage}.
The short answer: load fancyhdr, call \pagestyle{fancy}, wipe the defaults with \fancyhf{}, then assign \thepage to your chosen slot with \fancyfoot[C]{\thepage} or \fancyhead[R]{\thepage}. If chapter opening pages ignore your layout, redefine the plain style using \fancypagestyle{plain}.
Basic placement in headers and footers
The fancyhdr package assigns headers and footers through six standard positions: Left, Center, and Right for both head and foot.
| Target position | fancyhdr command | Typical use case |
|---|---|---|
| Bottom center | \fancyfoot[C]{\thepage} | Standard academic papers and general articles |
| Bottom right | \fancyfoot[R]{\thepage} | Technical reports, business documentation |
| Top right | \fancyhead[R]{\thepage} | Theses and dissertations following Chicago or APA |
| Top center | \fancyhead[C]{\thepage} | Manuscripts without running section headers |
| Top left | \fancyhead[L]{\thepage} | Documents where author or title occupies the right header |
By default, standard classes like article, report, and book use the plain page style, which centers an Arabic number in the footer. Activating fancyhdr requires loading the package, applying \pagestyle{fancy}, and clearing existing field values with \fancyhf{}.
Once cleared, you insert the \thepage counter macro into the exact field you want. If you omit \thepage, the document prints no page numbers at all.
Ready-to-use configurations
Choose the layout that matches your document structure and paste it directly into your preamble.
Single-sided document with bottom-right numbering
This setup places your name or project title in the top left, section titles in the top right, and the page number in the bottom right corner.
\documentclass{article} \usepackage{fancyhdr} \pagestyle{fancy} \fancyhf{} \fancyhead[L]{Project Report} \fancyhead[R]{\nouppercase{\rightmark}} \fancyfoot[R]{\thepage} \renewcommand{\headrulewidth}{0.4pt} \renewcommand{\footrulewidth}{0pt}Two-sided book layout with outer corner numbers
In books and duplex prints, numbers belong on the outer margins: the right side on odd pages and the left side on even pages. Use the E (even) and O (odd) selectors.
\documentclass[twoside]{book} \usepackage{fancyhdr} \pagestyle{fancy} \fancyhf{} \fancyhead[LE,RO]{\thepage} \fancyhead[RE]{\nouppercase{\leftmark}} \fancyhead[LO]{\nouppercase{\rightmark}} \renewcommand{\headrulewidth}{0.4pt}Total page count: Page X of Y
To display progress such as Page 3 of 12, combine fancyhdr with the lastpage package. The \pageref{LastPage} command reads the label generated on the final compilation pass.
\documentclass{article} \usepackage{lastpage} \usepackage{fancyhdr} \pagestyle{fancy} \fancyhf{} \fancyfoot[C]{Page \thepage\ of \pageref{LastPage}} \renewcommand{\headrulewidth}{0pt}Minimal header with top-right numbering and no rules
Many journals ask for a clean header containing only the page number on the upper right, with both decorative horizontal lines disabled.
\documentclass{article} \usepackage{fancyhdr} \pagestyle{fancy} \fancyhf{} \fancyhead[R]{\thepage} \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{0pt}
Fixing page numbers on chapter opening pages
A frequent source of confusion occurs when chapter start pages ignore your fancy settings and revert to bottom-center numbering.
| Desired chapter start page | Preamble command | Result |
|---|---|---|
| Match the fancy header exactly | \fancypagestyle{plain}{\pagestyle{fancy}} | Copies all running headers, rules, and page numbers onto chapter pages |
| Custom position without top headers | \fancypagestyle{plain}{\fancyhf{}\fancyfoot[R]{\thepage}\renewcommand{\headrulewidth}{0pt}} | Keeps top area clean but moves chapter page number to bottom right |
| Completely blank (no number) | \fancypagestyle{plain}{\fancyhf{}\renewcommand{\headrulewidth}{0pt}} | Suppresses numbers on all chapter first pages |
In LaTeX classes like report and book, the \chapter command calls \thispagestyle{plain} internally. It does this deliberately so that ornate headers and running titles do not crowd the chapter title banner.
Because plain is hard-coded into the chapter mechanism, changes made to the fancy pagestyle do not apply to these pages. To resolve this without editing document internals, use \fancypagestyle to adjust how plain behaves.
Changing the numeral style and resetting counters
The \thepage macro prints the current value formatted by the active \pagenumbering scheme.
| Command | Format produced | Sample output |
|---|---|---|
| \pagenumbering{arabic} | Standard Arabic numbers | 1, 2, 3, 4 |
| \pagenumbering{roman} | Lowercase Roman numerals | i, ii, iii, iv |
| \pagenumbering{Roman} | Uppercase Roman numerals | I, II, III, IV |
| \pagenumbering{alph} | Lowercase Latin letters | a, b, c, d |
| \pagenumbering{Alph} | Uppercase Latin letters | A, B, C, D |
You can switch between Arabic digits, Roman numerals, and letters at any point in the document. Calling \pagenumbering resets the page counter back to 1 automatically.
In standard book classes, \frontmatter and \mainmatter wrap this logic: \frontmatter activates \pagenumbering{roman}, while \mainmatter switches to \pagenumbering{arabic} and restarts the count.
Troubleshooting common fancyhdr issues
When page numbers disappear or land in unexpected spots, the cause is usually counter resets, package conflicts, or header height warnings.
Page number vanished after adding fancyhdr
If you invoked \fancyhf{} but forgot to define \fancyfoot or \fancyhead with \thepage, your headers and footers remain blank. Add \fancyfoot[C]{\thepage} to bring it back.
Package fancyhdr Warning: \headheight is too small
When headers include text and numbers, the default 12pt headheight is often insufficient. Add \setlength{\headheight}{14.5pt} or pass headheight=15pt to geometry in your preamble.
\usepackage[headheight=15pt]{geometry}Unwanted headers on blank pages before new chapters
In two-sided documents, clearpage calls can insert blank pages carrying running headers. Load the emptypage package to keep automatic blank pages clean.
\usepackage{emptypage}Page X of Y prints as Page X of ??
The lastpage package relies on cross-referencing. You must run pdfLaTeX or your chosen compiler at least twice to resolve the final page label.
Questions
Why did my page numbers disappear when I added fancyhdr?
Calling \fancyhf{} clears every header and footer field in the document. To show page numbers again, explicitly assign \thepage to a field such as \fancyfoot[C]{\thepage} or \fancyhead[R]{\thepage}.
How do I put page numbers in the top-right corner?
Clear the default layout using \fancyhf{}, then insert \fancyhead[R]{\thepage}. Make sure \pagestyle{fancy} is active in your preamble.
How do I format page numbers as Page X of Y?
Load the lastpage package with \usepackage{lastpage}, then define your footer with \fancyfoot[C]{Page \thepage\ of \pageref{LastPage}}. Compile the document twice so LaTeX can resolve the final page reference.
Why does the first page of each chapter ignore fancyhdr?
The \chapter command automatically calls \thispagestyle{plain}, overriding your fancy settings. Redefine that style in your preamble using \fancypagestyle{plain}{\pagestyle{fancy}} or give it custom footer commands.
How do I remove the horizontal line above or below the page number?
fancyhdr draws a 0.4pt rule under headers by default. Remove it by adding \renewcommand{\headrulewidth}{0pt} and \renewcommand{\footrulewidth}{0pt} to your preamble.
How do I set alternate page numbers for double-sided printing?
Use the two-sided position specifiers: E for even pages and O for odd pages. Writing \fancyfoot[LE,RO]{\thepage} puts numbers on the outer corners of both facing pages.
Can I use Roman numerals in the preface and Arabic in the body?
Yes. Place \pagenumbering{roman} before your front matter sections, then insert \pagenumbering{arabic} right before your first numbered section or chapter to reset the counter to 1.
What is the difference between \thepage and \value{page}?
\thepage is a formatted string macro representing the current page according to \pagenumbering, suitable for printing. \value{page} accesses the internal integer counter directly for mathematical comparisons.
Try your own paper in Texeno.
Start free, upload a project as a .zip and press Recompile. Upgrade when you need longer compiles.
Start writing