latex

How To Add Page Numbers in LaTeX

With page numbers, you can make a sequence of research papers. The page numbers also allow you to cite the pages and easily create a table of contents. Hence, it is always helpful to use page numbers in the document to make it more transparent for the readers.

In the document processors, you can use simple source code to add the page numbers in the technical documents. However, many new users don’t know the correct codes and sometimes have missing page numbers in the document. So, in this tutorial, we will explain various methods to add page numbers in LaTeX.

How To Add Page Numbers in LaTeX

Let’s start with a simple example of writing the table of contents and adding the page numbers.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lastpage}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\section{First section}
\blindtext
\section{Second section}
\blindtext
\blinddocument
\end{document}

 

Output


In the previous source code, we added \usepackage{blindtext} and \blindtext to create a sample text in the document.

Various Types of Page Numbers

If you want to add the text “page no.” with the page number, use the following source code:

\documentclass{article}
\usepackage{blindtext}
\usepackage{fancyhdr}

\begin{document}
\pagestyle{fancy}
\fancyhf{}
\cfoot{Page No. \thepage}

\tableofcontents
\newpage
\section{Introduction}
\blindtext
\newpage
\subsection{LaTeX Packages}
\blindtext
\newpage
\subsection{Source Code Commands}
\blindtext
\newpage
\blindtext
\newpage
\blindtext
\newpage
\blinddocument
\end{document}

 

Output


Now, let’s use the roman number using the \pagenumbering{roman} in the source code:

\documentclass{article}
\usepackage{blindtext}
\usepackage{fancyhdr}
\pagenumbering{roman}

\begin{document}
\pagestyle{fancy}
\fancyhf{}
\cfoot{Page No. \thepage}

\tableofcontents
\newpage
\section{Introduction}
\blindtext
\newpage
\subsection{LaTeX Packages}
\blindtext
\newpage
\subsection{Source Code Commands}
\blindtext
\newpage
\blindtext
\newpage
\blindtext
\newpage
\blinddocument
\end{document}

 

Output


You can also add different types of number forms simultaneously. For example, you can use the following source code to add various types of page numbers:

\documentclass{article}
\usepackage{inputenc}
\begin{document}
\pagenumbering{roman}
\tableofcontents
\newpage
\section{Introduction}
\newpage
\section{LaTeX Packages}
\newpage
\section{Source Code Commands}
\newpage
\section{LaTeX Examples}
\pagenumbering{arabic}

\subsection {Example 1}
\newpage
\subsection {Example 2}
\newpage
\subsection {Example 3}
\newpage
\subsection {Example 4}
\newpage
\pagenumbering{Alph}
\section{Answer Sheet}
\end{document}

 

Output


In the previous source code, we used inputenc \usepackage to compile the number format. Moreover, if you want to format alphabets into small letters, you can use the {alph} instead of {Alph}.

Additional Example

If you want to set a specific page number in the table of contents, you can use the following \setcounter{page} source code:

\documentclass{article}
\usepackage{inputenc}
\begin{document}

\pagenumbering{roman}

\tableofcontents
\newpage
\section{LaTeX Examples}
\pagenumbering{arabic}

\subsection {Example 1}
\newpage
\subsection {Example 2}
\setcounter{page}{5}
\newpage
\subsection {Example 3}
\newpage
\subsection {Example 4}
\setcounter{page}{8}
\newpage

\pagenumbering{Alph}
\section{Answer Sheet}

\end{document}

 

Output

Conclusion

This article discussed how you could easily add and resolve missing page numbers in LaTeX. Page numbers can be beneficial because they play an essential role in the table of contents to sort the sections down. Besides numbers, you can use the alphabet and roman numerals for the page numbers. Moreover, you can also add some info with the page numbers, such as Page No., Page, and Page Number.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.