Page LayoutPage X out Y in footer

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

Page X out Y in footer

Post by Tolaso »

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

Code: Select all

\cfoot{\thepage\ of \pageref{LastPage}}
of the fancyhdr package does not compile.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Page X out Y in footer

Post by rais »

you need to load the lastpage package for \pageref{LastPage} to work, AFAIR.

KR
Rainer
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Page X out Y in footer

Post by Stefan Kottwitz »

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.

Code: Select all

\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
LaTeX.org admin
Post Reply