Page Numbering in LaTeX: \pagenumbering, fancyhdr and Starting Pages
Quick answer
- Roman, then arabic:
\pagenumbering{roman}for the front matter, then\clearpageand\pagenumbering{arabic}, which restarts at 1. - Start at a given page number:
\setcounter{page}{1}(any number), after\pagenumbering. - No page number:
\thispagestyle{empty}for one page (after\maketitle),\pagestyle{empty}for all. - Built-in styles:
\pagestyle{plain}(number centred in the footer),headings(number in the header),empty. - Move the page number:
\usepackage{fancyhdr},\pagestyle{fancy},\fancyhf{}, then\fancyfoot[C]{\thepage}(or[R],[L],\fancyhead). - Page X of Y:
\usepackage{lastpage}and\fancyfoot[C]{Page \thepage\ of \pageref{LastPage}}.
How Page Numbering in LaTeX Works by Default
\thepage prints the page counter. 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.
Roman and Arabic Page Numbering: \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, CBecause 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}
\title{Report}
\author{A. Author}
\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}
\title{Thesis}
\author{A. Author}
\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.
Start Page Numbering at a Specific Page: \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 37A 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.
Remove the Page Number in LaTeX
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 beforeWith 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 documentThe Built-in Page Styles
| Style | Header | Footer |
|---|---|---|
empty | nothing | nothing |
plain | nothing | page number, centred |
headings | running title and page number | nothing |
myheadings | text you set with \markboth/\markright, and the page number | nothing |
\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.
Page Number Position in LaTeX: Bottom, Top, Left or Right
The built-in styles only offer two positions: centred in the footer (plain) or in the header next to the running title (headings). For any other position, load fancyhdr, clear its defaults and put \thepage in the slot you want. \fancyfoot is the footer, \fancyhead the header, and [L], [C], [R] pick left, centre and right:
\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear header and footer
\fancyfoot[R]{\thepage} % page number bottom right
% \fancyhead[R]{\thepage} % ...or top right instead
\renewcommand{\headrulewidth}{0pt} % no line under the header
% Title and chapter pages use the plain style: give it the same footer
\fancypagestyle{plain}{\fancyhf{}\fancyfoot[R]{\thepage}}
\title{Notes}
\author{A. Author}
\begin{document}
\maketitle
\section{Introduction}
The number sits in the bottom right corner of every page.
\end{document}The \fancypagestyle{plain} line matters: without it the title page still shows the default centred number, because \maketitle and \chapter switch that page to plain. Formatting goes inside the slot too, for example \fancyfoot[C]{\textbf{\thepage}} or \fancyfoot[C]{-- \thepage\ --}.
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{fancyhdr}
\usepackage{lastpage}
\usepackage{hyperref}
\pagestyle{fancy}
\fancyfoot[C]{Page \thepage\ of \pageref*{LastPage}}LastPage reports the number as printed on the last page, not the physical PDF page count. A book with six roman front-matter pages and twenty arabic pages ends at 20, not 26. Show only the roman page number in the front matter and enable “Page X of Y” in the main matter, as in the complete example below. This assumes arabic numbering continues through the final page; resetting it for an appendix makes LastPage unsuitable as a body total.
\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 Errors
| Symptom | Cause | Fix |
|---|---|---|
| No page number on the first page, numbers elsewhere | The first page uses plain (set by \maketitle or \chapter) while your fancy style puts the number in the header | Redefine plain with \fancypagestyle, or write \thispagestyle{fancy} after \maketitle |
Title page shows a number although \thispagestyle{empty} is present | The command came before \maketitle, which sets plain afterwards | Move it after \maketitle |
| destination with the same identifier (name{page.1}) has been already used | Two pages print the same \thepage, typically a counted title page and body page 1 | Use roman numbering for the front matter, or \hypersetup{pageanchor=false} on the unnumbered pages |
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}
\newcommand{\pagefooter}{\thepage}
\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\@chapapp\ \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]{\pagefooter}
\renewcommand{\headrulewidth}{0.4pt}
% Chapter opening pages: footer only, no header rule
\fancypagestyle{plain}{%
\fancyhf{}%
\fancyfoot[C]{\pagefooter}%
\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 ...
\renewcommand{\pagefooter}{Page \thepage\ of \pageref*{LastPage}}
\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}Frequently Asked Questions
How do I add page numbers in LaTeX?
Page numbers are on by default: the article, report and book classes print \thepage in the footer or header of every page. If they are missing, a \pagestyle{empty} or \thispagestyle{empty} has switched them off; put \pagestyle{plain} after \begin{document} for a centred number in the footer, or use fancyhdr with \fancyfoot[C]{\thepage}.
How do I start page numbering from a specific page in LaTeX?
Write \setcounter{page}{n} at the point where the numbering should change; that page is then numbered n. If you also switch the style, put \clearpage, then \pagenumbering{arabic}, then \setcounter{page}{n}, because \pagenumbering resets the counter to 1.
How do I remove the page number from the first page?
Put \thispagestyle{empty} on that page. In an article with \maketitle it must come after \maketitle, which sets the plain style on the title page itself. To remove page numbers from every page, use \pagestyle{empty} instead.
How do I use roman numerals for the front matter and arabic numbers after?
Write \pagenumbering{roman} at the start of the document and \clearpage followed by \pagenumbering{arabic} where the main text begins; the arabic numbering restarts at 1. In the book class, \frontmatter and \mainmatter do both switches for you.
How do I put the page number in the bottom right or top right corner?
Load fancyhdr, then write \pagestyle{fancy}, \fancyhf{} to clear the defaults, and \fancyfoot[R]{\thepage} for the bottom right or \fancyhead[R]{\thepage} for the top right. L and C give the left and centre positions. Redefine the plain style with \fancypagestyle{plain} if title and chapter pages should match.
How do I show "Page X of Y" in LaTeX?
Load the lastpage package and write the total as \pageref{LastPage}, for example \fancyfoot[C]{Page \thepage\ of \pageref{LastPage}} with fancyhdr. Compile twice so the label is known; with hyperref use \pageref*{LastPage} to avoid a link.
Next Steps
Page numbers sorted? Keep working on the layout:
- Table of Contents in LaTeX –
\tableofcontents, depth, roman-numbered contents pages and tocloft styling - Page Size & Margins – Paper size, margins and
headheightwith the geometry package - Horizontal Lines in LaTeX – Header and footer rules,
\hrule,\ruleand table rules - LaTeX Hyperlinks – hyperref, link colors and the duplicate page anchor warning
Free LaTeX Tools
- LaTeX Preview – Test page styles and fancyhdr settings with a live PDF preview
- AI LaTeX Generator – Generate LaTeX from text descriptions
- LaTeX Symbols Reference – Browse math operators and special characters
Fix page numbering faster with AI
Open the complete example in Octree and compare the roman front matter with the arabic body pages. Ask the AI assistant to explain a numbering warning, then check the title page, chapter openers and final footer in the compiled PDF.
Try Octree Free →