Page numbering
Document page numbers can be typeset using a particular style, such as using Arabic or Roman numerals, and typeset at a particular page location—usually within headers or footers. This article shows how the style and location of page numbers can be changed:
- the style of page numbers can be changed by the
\pagenumbering
command; - the location of page numbers can be changed using the
fancyhdr
package.
Setting the style of page numbers
The style of page numbers can be changed using the command
\pagenumbering{⟨style⟩}
where ⟨style⟩
is one of
arabic
: use Arabic numerals (1, 2, 3, ...)alph
: use lowercase letters (a, b, c, ...)Alph
: use uppercase letters (A, B, C, ...)roman
: use lowercase roman numerals (i, ii, iii, ...)Roman
: use uppercase roman numerals (I, II, III, ...)
Example to demonstrate page number styles
The following example typesets a table of contents followed by 5 pages, each of which demonstrates one of the ⟨style⟩
options for page numbers. Internally, LaTeX uses a so-called counter to record the current page number. A counter is the name of a LaTeX variable used to store an integer value—see the Overleaf Counters article for more detail and examples.
\begin{document}
% Insert a table of contents
\tableofcontents
\newpage
\section{Uppercase Roman}
\pagenumbering{Roman}% Capital 'R': uppercase Roman numerals
\blindtext[1]
\newpage
\section{Lowercase Roman} % lowercase Roman numerals
\pagenumbering{roman}
\blindtext[1]
\newpage
\section{Arabic numbers}
\pagenumbering{arabic} % Arabic/Indic page numbers
\blindtext[1]
\newpage
\section{Lowercase alphabetic}
\pagenumbering{alph} % Lowercase alphabetic page "numbers"
\blindtext[1]
\newpage
\section{Uppercase alphabetic}
\pagenumbering{Alph} % Uppercase alphabetic page "numbers"
\blindtext[1]
\end{document}
The next graphic shows the table of contents produced by this document. Note how the \pagenumbering
command has reset the starting page number to the initial value for each style: i
for the roman
style, A
for the Alph
style, I
for the Roman
style and so forth:
Here are two sample pages produced by this example; the first image shows page numbers as uppercase Roman numbers, the second demonstrates page numbers as uppercase letters:
Book class: using two styles of page number
The first few pages of a book, which include the copyright page, title or half-title page, any Foreword or Preface and table of contents, are collectively called the preliminary pages, or prelims for short—another term for those pages is front matter. Traditionally, prelim pages are numbered using lowercase Roman numerals with the main (body) pages being numbered using Arabic numerals. The book
document class contains commands to assist with this, as the following example demonstrates.
\documentclass{book}
% The emptypage package prevents page numbers and
% headings from appearing on empty pages.
\usepackage{emptypage}
\begin{document}
\frontmatter %Use lowercase Roman numerals for page numbers
\chapter*{Foreword}
\addcontentsline{toc}{chapter}{Foreword}
The Foreword is written by someone who is not the book's author.
\chapter*{Preface}
\addcontentsline{toc}{chapter}{Preface}
The Preface is written by the book's author.
\tableofcontents
\mainmatter % Now Use Arabic numerals for page numbers
\chapter{First Chapter}
This will be an empty chapter...
\section{First section}
Some text would be good.
\chapter{The second chapter}
\end{document}
The table of contents produced by this example demonstrates the use of Roman numerals for the front matter and Arabic numerals for the main (body) matter:
The commands that control the page numbering are:
\frontmatter
: Pages after this command and before the command\mainmatter
, will be numbered with lowercase Roman numerals.
\mainmatter
: This will restart the page counter and change the style to Arabic numbers.
Article class: using two styles of page number
As noted above, the current page number is stored in a LaTeX counter variable which is called page
. The value stored in page
, or any other counter variable, can be set to a specific value using the \setcounter
command:
\setcounter{⟨countvar⟩}{⟨intval⟩}
where the counter variable ⟨countvar⟩
is set to the value ⟨intval⟩
. For example, to set the page
counter to 3
you would write
\setcounter{page}{3}
Other commands to change counter variables include \addtocounter
and \stepcounter
:
\addtocounter{⟨countvar⟩}{⟨increment⟩}
\stepcounter{⟨countvar⟩}
\addtocounter{⟨countvar⟩}{⟨increment⟩}
adds an amount⟨increment⟩
to the counter variable⟨countvar⟩
. Note:⟨increment⟩
can be positive, to increase the counter value, or negative to decrease it.\steptocounter{⟨countvar⟩}
adds 1 to the counter variable⟨countvar⟩
This hypothetical example modifies the page counter to plan a table of contents, including sections that haven't been written and whose page count is estimated. It also uses \pagenumbering{roman}
and \pagenumbering{Arabic}
to set the stye of page numbers.
\documentclass{article}
\pagenumbering{roman}
\begin{document}
\section*{Guest Foreword (TBD)}
\addcontentsline{toc}{section}{Foreword: 4 pages (TBD)}
To be written: Allowing 4 pages.
\newpage
\setcounter{page}{5}
\section*{Introduction (2 pages)}
\addcontentsline{toc}{section}{Introduction: 2 pages (TBD)}
To be written: 2 pages allowed.
\newpage
\addtocounter{page}{1}
\section*{Strategy summary (2 pages)}
\addcontentsline{toc}{section}{Strategy summary: 2 pages (TBD)}
To be written: 2 pages.
\newpage
\stepcounter{page}
\tableofcontents
\newpage
\pagenumbering{arabic}
\section{Level 1 heading}
Some text on this page.
\newpage
\section{Another Level 1 heading}
\end{document}
Open this example in Overleaf.
This example produces the following table of contents, showing the results of altering the value of the page
counter:
Customizing page numbers with the fancyhdr
package
The fancyhdr
package can be used to customize the location and format of page numbers; for example, placing them at specific positions within the header or footer. The Overleaf article Headers and footers explores this in detail, with many examples we won't reproduce here.
Here we'll give one example of writing the current page number in the context of the total page count, such as Page X of Y
where Y is the total number of document pages obtained using the lastpage
package.
\documentclass{article}
% Use a small page size to avoid
% needing lots of text to create
% several pages
\usepackage[includefoot,
paperheight=10cm,
paperwidth=10cm,
textwidth=9cm,
textheight=8cm]{geometry}
\usepackage{blindtext}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear existing header/footer entries
% Place Page X of Y on the right-hand
% side of the footer
\fancyfoot[R]{Page \thepage \hspace{1pt} of \pageref{LastPage}}
\begin{document}
% Insert a table of contents
\tableofcontents
\newpage
\section{One}
\blindtext[1]
\newpage
\section{Two}
\blindtext[1]
\newpage
\section{Three}
\blindtext[1]
\newpage
\section{Four}
\blindtext[1]
\newpage
\section{Five}
\blindtext[1]
\end{document}
Open this example in Overleaf.
The following image shows one of the pages produced by this example—note Page 3 of 6
on the right-hand side of the footer:
Overleaf guides
- Creating a document in Overleaf
- Uploading a project
- Copying a project
- Creating a project from a template
- Using the Overleaf project menu
- Including images in Overleaf
- Exporting your work from Overleaf
- Working offline in Overleaf
- Using Track Changes in Overleaf
- Using bibliographies in Overleaf
- Sharing your work with others
- Using the History feature
- Debugging Compilation timeout errors
- How-to guides
- Guide to Overleaf’s premium features
LaTeX Basics
- Creating your first LaTeX document
- Choosing a LaTeX Compiler
- Paragraphs and new lines
- Bold, italics and underlining
- Lists
- Errors
Mathematics
- Mathematical expressions
- Subscripts and superscripts
- Brackets and Parentheses
- Matrices
- Fractions and Binomials
- Aligning equations
- Operators
- Spacing in math mode
- Integrals, sums and limits
- Display style in math mode
- List of Greek letters and math symbols
- Mathematical fonts
- Using the Symbol Palette in Overleaf
Figures and tables
- Inserting Images
- Tables
- Positioning Images and Tables
- Lists of Tables and Figures
- Drawing Diagrams Directly in LaTeX
- TikZ package
References and Citations
- Bibliography management with bibtex
- Bibliography management with natbib
- Bibliography management with biblatex
- Bibtex bibliography styles
- Natbib bibliography styles
- Natbib citation styles
- Biblatex bibliography styles
- Biblatex citation styles
Languages
- Multilingual typesetting on Overleaf using polyglossia and fontspec
- Multilingual typesetting on Overleaf using babel and fontspec
- International language support
- Quotations and quotation marks
- Arabic
- Chinese
- French
- German
- Greek
- Italian
- Japanese
- Korean
- Portuguese
- Russian
- Spanish
Document structure
- Sections and chapters
- Table of contents
- Cross referencing sections, equations and floats
- Indices
- Glossaries
- Nomenclatures
- Management in a large project
- Multi-file LaTeX projects
- Hyperlinks
Formatting
- Lengths in LaTeX
- Headers and footers
- Page numbering
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Page size and margins
- Single sided and double sided documents
- Multiple columns
- Counters
- Code listing
- Code Highlighting with minted
- Using colours in LaTeX
- Footnotes
- Margin notes
Fonts
Presentations
Commands
Field specific
- Theorems and proofs
- Chemistry formulae
- Feynman diagrams
- Molecular orbital diagrams
- Chess notation
- Knitting patterns
- CircuiTikz package
- Pgfplots package
- Typesetting exams in LaTeX
- Knitr
- Attribute Value Matrices
Class files
- Understanding packages and class files
- List of packages and class files
- Writing your own package
- Writing your own class