Document Structure

Page Numbering in LaTeX

Learn how page numbering works in LaTeX, including changing number styles, hiding page numbers, using Roman numerals for front matter, and Page X of Y.

On this page
  1. Automatic page numbers
  2. Change the number style with \pagenumbering
  3. Hide page numbers
  4. Move page numbers to the header
  5. Custom placement with fancyhdr
  6. Front matter and main matter
  7. Set a starting number
  8. Troubleshooting

LaTeX numbers pages for you. In article, report, and book, the number appears at the bottom center of each page in Arabic numerals (1, 2, 3, and so on) by default. This guide covers how to change that style, hide numbers, restart the count, and move the number to a header or a corner.

Automatic page numbers

You do not need to add anything for page numbers to appear. LaTeX prints the current page number from the \thepage command in the default footer. Use the commands below only when the default does not fit your document.

Change the number style with \pagenumbering

The \pagenumbering command sets the style. The most common styles are:

Command Output
\pagenumbering{arabic} 1, 2, 3
\pagenumbering{roman} i, ii, iii
\pagenumbering{Roman} I, II, III
\pagenumbering{alph} a, b, c
\pagenumbering{Alph} A, B, C
\pagenumbering{gobble} No number printed, but pages are still counted

The command also resets the page counter to 1. To make the new style start on a fresh page, put \clearpage before it:

\clearpage
\pagenumbering{roman}

Hide page numbers

Use one of these page styles, depending on how much you want to hide:

  • \thispagestyle{empty} hides the number on one page, such as a title page. Place it after \maketitle to affect the title page.
  • \pagestyle{empty} hides the number on every page that follows.
  • \pagenumbering{gobble} keeps counting pages but prints no number, as shown in the table above.
\maketitle
\thispagestyle{empty}

Move page numbers to the header

The headings page style prints the page number in the header, next to the running heading. To return the number to the bottom center, use plain:

\pagestyle{headings}   % number in the header
\pagestyle{plain}      % number at the bottom center

Custom placement with fancyhdr

The fancyhdr package places the number wherever you want in the header or footer. This example puts it at the right of the footer and removes the line above the footer:

\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}                    % clear the default header and footer
\fancyfoot[R]{\thepage}       % page number at the right of the footer
\renewcommand{\headrulewidth}{0pt}

To print “Page X of Y”, load lastpage and use \pageref{LastPage} for the total:

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

The total updates after two compiles, so compile again if the number looks wrong.

For a smaller page number, wrap it in a size command, such as \fancyfoot[C]{\footnotesize\thepage}. LaTeX does not require a particular size. Choose the size that your template or publisher asks for. For how headers and footers behave on chapter opening pages, see headers, footers and two-sided layouts in LaTeX.

Front matter and main matter

A book has built-in commands for this. \frontmatter uses lowercase Roman numerals, and \mainmatter switches to Arabic numerals and restarts the count at 1:

\documentclass{book}

\begin{document}

\frontmatter
\tableofcontents

\mainmatter
\chapter{Introduction}
Text of the first chapter.

\end{document}

In article and report, use \pagenumbering at the boundary instead. Put \clearpage first, then \pagenumbering{roman} before the front matter and \pagenumbering{arabic} before the main text.

Set a starting number

To start the count at a specific number, place \setcounter{page}{N} right after a \clearpage. The next page then shows N:

\clearpage
\setcounter{page}{5}

Troubleshooting

  • A number appears on the title page. Add \thispagestyle{empty} after \maketitle.
  • The numbering style changes one page too early or late. Put \clearpage before \pagenumbering or \setcounter.
  • “Page X of Y” shows the wrong total. Compile the document again.
  • A custom header or footer does not show on chapter opening pages. Those pages use the plain style. See headers, footers and two-sided layouts in LaTeX for the fix.

If the numbers are for a table of contents in front matter, see table of contents, lists and nomenclature in LaTeX for how the list fits into that setup.

The complete guide to document structure

Chapters in LaTeX: Document Classes and Chapter Styles
Read the guide

Keep exploring

Guides from other topics

All topics →