LaTeX Page Numbering: Roman, Arabic, Starting Pages and fancyhdr

LaTeX numbers pages automatically, but almost every real document needs more than the default: roman numerals for the front matter, no number on the title page, a number that starts at a given value, or “Page 3 of 12” in the footer. This guide covers \pagenumbering, \setcounter, the built-in page styles, the fancyhdr package, chapter-based numbering, Beamer frame numbers, and the errors people run into along the way.

How LaTeX Numbers Pages by Default

Every page has a counter called page, and the command \thepage prints it. In article the first page is 1, the number is printed centred in the footer (page style plain), and the title made by \maketitle is numbered like any other page. In book and report the title page is a page of its own without a number. report keeps the plain style, while bookdefaults to headings: the number sits in the outer corner of the header next to the running chapter or section title.

Changing the Numeral Style: \pagenumbering

\pagenumbering{style} switches the numeral style and resets the counter to 1. The five built-in styles are:

\pagenumbering{arabic}  % 1, 2, 3   (default)
\pagenumbering{roman}   % i, ii, iii
\pagenumbering{Roman}   % I, II, III
\pagenumbering{alph}    % a, b, c   (only up to 26 pages)
\pagenumbering{Alph}    % A, B, C

Because the counter is reset, you normally issue the command right after a page break. The classic article layout with a roman-numbered table of contents and an arabic-numbered body looks like this:

\documentclass{article}
\begin{document}
\pagenumbering{roman}     % i, ii, ...
\maketitle
\tableofcontents
\clearpage
\pagenumbering{arabic}    % back to 1, 2, ...

\section{Introduction}
Body text starts on page 1.
\end{document}

Always put \clearpage (or \cleardoublepage in two-sided documents) before the switch. The page counter is read when a page is shipped out, so changing the style mid-page would affect the page you are still on.

Front Matter and Main Matter in book

The book class has three commands that do the switching for you and also control chapter numbering:

\documentclass{book}
\begin{document}
\frontmatter   % roman page numbers; \chapter is unnumbered
\maketitle
\tableofcontents
\chapter{Preface}

\mainmatter    % arabic page numbers restart at 1; chapters numbered
\chapter{Introduction}

\appendix      % chapters lettered A, B, ...; page numbers continue
\chapter{Data Tables}

\backmatter    % chapters unnumbered again; page numbers continue
\chapter{Bibliography}
\end{document}

\frontmatter calls \pagenumbering{roman}, \mainmatter calls \pagenumbering{arabic}, and both start with \cleardoublepage. The report and article classes do not define these commands; use the manual \pagenumbering sequence above, or load the memoir class, which has them.

Starting at a Specific Page Number: \setcounter

To start a chapter extracted from a larger work at page 37, or to continue the numbering of a previous volume, set the counter directly. Do it after \pagenumbering, because that command resets the counter:

\clearpage
\pagenumbering{arabic}
\setcounter{page}{37}   % this page is numbered 37

A common variant is a document whose title page is counted but not printed. With \setcounter{page}{0} before a hand-made title page the first body page comes out as 1 (\maketitle in book and report resets the counter itself, so this trick does not work there); with \setcounter{page}{2} after the title page the title is implicitly page 1.

Removing the Page Number

On the title page

\thispagestyle{empty} removes header and footer from the current page only. In article, \maketitle sets the page style of the title page itself, so the command has to come after it:

\maketitle
\thispagestyle{empty}   % after \maketitle, not before

With the titlepage class option, or in book and report, the title page is already empty. The same trick works for a hand-made titlepage environment, a dedication, or any page that should carry no number.

On chapter opening pages

\chapter issues \thispagestyle{plain} for its first page, which is why chapter openers show a centred number even when the rest of the document uses headings or fancy. To change what those pages look like, redefine the plain style rather than fighting each chapter. With fancyhdr:

\usepackage{fancyhdr}
\fancypagestyle{plain}{%
  \fancyhf{}%                            % clear header and footer
  \renewcommand{\headrulewidth}{0pt}%    % no rule
}

That makes every chapter opener completely blank. To keep the number but drop the header, add \fancyfoot[C]{\thepage} inside the definition.

Everywhere

\pagestyle{empty}   % no headers or footers in the whole document

The Built-in Page Styles

StyleHeaderFooter
emptynothingnothing
plainnothingpage number, centred
headingsrunning title and page numbernothing
myheadingstext you set with \markboth/\markright, and the page numbernothing

\pagestyle{...} applies from the current page onward; \thispagestyle{...} affects one page. For myheadings, set the text with \markboth{left header}{right header} (two-sided) or \markright{header} (one-sided). Anything beyond these four styles is the job of fancyhdr.

Custom Headers and Footers with fancyhdr

fancyhdr gives you six slots: left, centre and right in both header and footer. Start by clearing them with \fancyhf{}, then fill the ones you need:

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}                           % clear all six fields
\fancyhead[L]{\leftmark}             % chapter or section title
\fancyhead[R]{Draft, October 2026}
\fancyfoot[C]{\thepage}              % page number, centred footer
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}

\leftmark holds the current chapter title (or section title in article) and \rightmark the current section (or subsection). The default fancy style uppercases them; wrap the mark in \nouppercase if you prefer mixed case.

Two-sided documents: E and O

With the twoside class option the slot letters can be combined with E (even pages) and O (odd pages). The usual book layout puts the page number on the outer edge:

\documentclass[twoside]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}            % outer corner: left on even, right on odd
\fancyhead[RE]{\nouppercase{\leftmark}}   % chapter on even pages
\fancyhead[LO]{\nouppercase{\rightmark}}  % section on odd pages

“Page X of Y” with lastpage

The lastpage package writes a label on the final page, so the total is \pageref{LastPage}. It needs two compilations to settle, and with hyperref you will usually want the unlinked \pageref*:

\usepackage{lastpage}
\usepackage{hyperref}
\fancyfoot[C]{Page \thepage\ of \pageref*{LastPage}}

LastPage reports the number as printed on the last page. If the back matter is numbered differently from the body, the total will reflect that, so place the switch to arabic before the first page that shows “of Y”.

\headheight

Headers taller than the default 12pt trigger the warning “\headheight is too small (12.0pt): Make it at least 14.5pt”. Set the length once in the preamble, either directly or through geometry:

\setlength{\headheight}{15pt}
% or
\usepackage[a4paper, margin=2.5cm, headheight=15pt]{geometry}

Custom Number Formats: Redefining \thepage

\pagenumbering is really two things: a reset of the counter and a redefinition of \thepage. If you want a different format without restarting at 1, redefine \thepage yourself. The same technique produces prefixed numbers for appendices or supplements:

% Switch to Roman numerals but keep counting
\renewcommand{\thepage}{\Roman{page}}

% Appendix pages as A-1, A-2, ... (page counter restarted)
\appendix
\clearpage
\setcounter{page}{1}
\renewcommand{\thepage}{A-\arabic{page}}

With hyperref, \thepage must produce a different string for every page, otherwise you get “destination with the same identifier has been already used” warnings and links that jump to the wrong page. The prefix in the example above keeps the labels unique.

Numbering Across \include and \input Files

A document assembled from several files with \include or \input has one page counter, so numbering continues from file to file with no extra work. Two things break it: a \pagenumbering or \setcounter{page} left at the top of a chapter file, and compiling a chapter on its own with the subfiles package, where the counter naturally starts at 1 because nothing precedes it. With \includeonly the page numbers of the skipped files are taken from their .aux files, so the compiled chapters keep their final numbers after one full run.

Restarting Page Numbers in Every Chapter

Manuals and standards sometimes number pages 1-1, 1-2, 2-1, 2-2. The tempting one-liner \counterwithin{page}{chapter} does not work: it resets page to 0 at the moment \chapter steps the chapter counter, which is after the page break, so every chapter opener prints 0. Use the chappg package, which defines a bychapter numbering style and handles front matter, appendices and the separator correctly:

\documentclass{report}
\usepackage{chappg}        % pages are numbered 1-1, 1-2, 2-1, ...
\renewcommand{\chappgsep}{--}   % optional: en dash instead of hyphen
\begin{document}
\pagenumbering{bychapter}  % issued automatically unless you load [noauto]
\chapter{First}
\chapter{Second}
\end{document}

If you prefer not to add a package, hook the reset onto \chapter with etoolbox. The reset happens before the chapter's own page break, so the opener is page 1:

\usepackage{etoolbox}
\pretocmd{\chapter}{\cleardoublepage\setcounter{page}{1}}{}{}
\renewcommand{\thepage}{\thechapter-\arabic{page}}

Frame Numbers in Beamer

Beamer slides have a frame counter rather than a page counter. Most themes hide it; the quickest way to show “3 / 20” is the built-in footline template:

\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}      % remove the navigation bar
\setbeamertemplate{footline}[frame number]    % "3 / 20" bottom right

% or build your own footline
\setbeamertemplate{footline}{%
  \hfill\insertframenumber\,/\,\inserttotalframenumber
  \hspace{2em}\vspace{1em}%
}

\insertframenumber and \inserttotalframenumber are the two macros to know; the total is read from the .aux file, so it needs a second compile. Backup slides should not count: give them the [noframenumbering] frame option, or load appendixnumberbeamer and put \appendix before them, which also restarts the frame count for the appendix.

Common Problems and Fixes

SymptomCauseFix
No page number on the first page, numbers elsewhereThe first page uses plain (set by \maketitle or \chapter) while your fancy style puts the number in the headerRedefine plain with \fancypagestyle, or write \thispagestyle{fancy} after \maketitle
Numbering restarts at 1 after changing the style\pagenumbering always resets the counterRedefine \thepage instead, or add \setcounter{page}{n} afterwards
\headheight is too small warning, header overlaps textMulti-line or large-font header in fancyhdr\setlength{\headheight}{15pt} or headheight=15pt in geometry
Title page shows a number although \thispagestyle{empty} is presentThe command came before \maketitle, which sets plain afterwardsMove it after \maketitle
\pageref{LastPage} prints ??The label is written at the end of the runCompile twice
destination with the same identifier (name{page.1}) has been already usedTwo pages print the same \thepage, typically a counted title page and body page 1Use roman numbering for the front matter, or \hypersetup{pageanchor=false} on the unnumbered pages
Chapter opener numbered 0\counterwithin{page}{chapter}Use chappg or the \pretocmd hook above
Page number on the wrong side in a two-sided bookRoman and arabic sections start on even pages, or twoside is missingUse \cleardoublepage before each switch and check the class option

Complete Example

A two-sided book with roman front matter, arabic main matter, running heads, a “Page X of Y” footer and clean chapter openers:

\documentclass[11pt, twoside]{book}
\usepackage[a4paper, margin=2.5cm, headheight=15pt]{geometry}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{hyperref}

\pagestyle{fancy}
% fancyhdr's \chaptermark ignores \frontmatter, so front-matter chapters
% would get "Chapter 0." in the running head; this version checks it
\makeatletter
\renewcommand{\chaptermark}[1]{%
  \markboth{\if@mainmatter\chaptername\ \thechapter.\ \fi #1}{}}
\makeatother
\fancyhf{}
\fancyhead[LE]{\nouppercase{\leftmark}}     % chapter title on even pages
\fancyhead[RO]{\nouppercase{\rightmark}}    % section title on odd pages
\fancyfoot[C]{Page \thepage\ of \pageref*{LastPage}}
\renewcommand{\headrulewidth}{0.4pt}

% Chapter opening pages: footer only, no header rule
\fancypagestyle{plain}{%
  \fancyhf{}%
  \fancyfoot[C]{Page \thepage\ of \pageref*{LastPage}}%
  \renewcommand{\headrulewidth}{0pt}%
}

\title{Page Numbering in Practice}
\author{A. Author}

\begin{document}
\frontmatter                 % i, ii, iii ...
\maketitle                   % unnumbered title page in book
\tableofcontents
\chapter{Preface}
Front-matter pages carry lowercase roman numerals.

\mainmatter                  % 1, 2, 3 ...
\chapter{Introduction}
The opening page of each chapter uses the redefined \texttt{plain}
style; every other page uses \texttt{fancy}.
\section{Running Heads}
Even pages show the chapter, odd pages show the section.

\appendix
\chapter{Extra Material}
Appendix pages continue the arabic sequence.
\end{document}

Quick Reference

TaskCommand
Roman numerals (resets to i)\pagenumbering{roman}
Arabic numerals (resets to 1)\pagenumbering{arabic}
Start at page 5\setcounter{page}{5}
No number on this page\thispagestyle{empty} (after \maketitle)
No numbers anywhere\pagestyle{empty}
Number only, centred footer\pagestyle{plain}
Running heads with number\pagestyle{headings}
Front/main matter switch (book)\frontmatter / \mainmatter
Number in footer with fancyhdr\fancyhf{} \fancyfoot[C]{\thepage}
Number on the outer edge (twoside)\fancyhead[LE,RO]{\thepage}
Page X of Y\fancyfoot[C]{Page \thepage\ of \pageref{LastPage}} with lastpage
Blank chapter openers\fancypagestyle{plain}{\fancyhf{}\renewcommand{\headrulewidth}{0pt}}
Change format without reset\renewcommand{\thepage}{\Roman{page}}
Per-chapter numbering 2-1, 2-2\usepackage{chappg}
Fix header height warning\setlength{\headheight}{15pt}
Beamer frame numbers\setbeamertemplate{footline}[frame number]

Next Steps

Page numbers sorted? Keep working on the layout:

Free LaTeX Tools

Fix page numbering faster with AI

Octree's AI editor sets up front matter, fancyhdr headers and page styles for you, explains the warnings, and compiles your document in seconds.

Try Octree Free →