LaTeX forum ⇒ Page LayoutPage 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).
Posts: 37
Joined: Tue Dec 20, 2016 12:23 am

Page X out Y in footer

Postby Tolaso » Mon Aug 28, 2017 9:54 pm

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 but unfortunately none of those worked for me.

For example

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

of the fancyhdr package does not compile.


Posts: 160
Joined: Sun Nov 16, 2014 8:51 pm

Postby rais » Mon Aug 28, 2017 10:05 pm

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


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

Postby Stefan Kottwitz » Wed Dec 27, 2017 8:36 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.

  1. \documentclass{article}
  2. \usepackage{fancyhdr}
  3. \pagestyle{fancy}
  4. \usepackage{blindtext}
  5. \usepackage{lastpage}
  6. \cfoot{\thepage\ of \pageref{LastPage}}
  7. \begin{document}
  8. \Blinddocument
  9. \end{document}

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

Site admin

Return to “Page Layout”

Who is online

Users browsing this forum: No registered users and 4 guests