[LaTeX] Use fancyhdr package to control page numbering style

This post introduces how to use fancyhdr package to control page numbering style in your LaTex document.

We can use the LaTeX package fancyhdr to customize how the page numbers are displayed.

For example, if you want to put the current page number in the context of the page numbers in the whole document (page 1 of 10 or 1/10), the following command can help you with that:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{lastpage}
 
\pagestyle{fancy}
\fancyhf{}


%use the following commands by uncomment (i.e., remove the % for the line you want to use.) 

%uncomment the command below (the part in bold) if you want to show the %style "Page 1 of 10" to the right of your footer)
%\rfoot{Page \thepage \hspace{1pt} of \pageref{LastPage}} 
% change \rfoot to \lfoot or \cfoot for left or center positioning

%uncomment the command below (the part in bold) if you want to show the style "1/10" to the right of your footer)
%\rfoot{\thepage \hspace{1pt}/\pageref{LastPage}} 
% change \rfoot to lfoot or \cfoot for left or center positioning

%uncomment the command below (the part in bold) if you only want to put %the current page number at the center of the header
%\fancyhead[C]{\thepage} 
% change [C] to [R] or [L] for right or left positioning 


 
\begin{document}
 
\tableofcontents
 
\section{First section}
Some text...
 
\section{Second section}
More text...
 
\end{document}

See the references given below for more style needs (e.g., even and odd page numbering).

References:

Page numbering/ Customizing numbering styles

LaTeX/Customizing Page Headers and Footers

 

Leave a Reply

Your email address will not be published. Required fields are marked *