## LaTeX forum ⇒ Page Layout ⇒ Page X out Y in footer Topic is solved

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Tolaso
Posts: 37
Joined: Tue Dec 20, 2016 12:23 am

### Page X out Y in footer

Suppose that one of my documents has 21 pages. I want to display in the footer Page X of 21. How can I do that? I have read some commands in tex.stackexchange.com but unfortunately none of those worked for me.

For example

\cfoot{\thepage\ of \pageref{LastPage}}

of the fancyhdr package does not compile.

Tags:

rais
Posts: 160
Joined: Sun Nov 16, 2014 8:51 pm
you need to load the lastpage package for \pageref{LastPage} to work, AFAIR.

KR
Rainer

Stefan Kottwitz
Posts: 8954
Joined: Mon Mar 10, 2008 9:44 pm
I agree with Rainer. An additional remark: you need to compile at least two times. At the very first time, the reference to the last page is unknown, as it's computed during the compiler run. At the second time, you will see that it works: check out this example, you will get "Page 1 of 16" etc.

\documentclass{article}\usepackage{fancyhdr}\pagestyle{fancy}\usepackage{blindtext}\usepackage{lastpage}\cfoot{\thepage\ of \pageref{LastPage}}\begin{document}\Blinddocument\end{document}

One click on "Open in Overleaf" above the code proves it - the online compiler does the second run automatically.

Stefan