My goal is to achieve n of m type page numbering if the document has more than 1 page and no page numbers otherwise. I have no problem putting n of m page numbers thanks to How can I add "page # of ##" on my document?. My plan was to use the totcount package to test the total number of pages. The problem is that the lastpage package screws up the total count. Specifically, the resulting 1 page document of the following MWE:

totcount: \total{page}

lastpage: \pageref{LastPage}

has \total{page} equal to 2 while \pageref{LastPage} is equal to 1.

Any ideas what is going on?


2 Answers 2


Perhaps this doesn't answer the question completely, but it provides a work-around (circumventing totcount):

enter image description here

\usepackage[paper=a6paper]{geometry}% http://ctan.org/pkg/geometry
\usepackage{fancyhdr,refcount}% http://ctan.org/pkg/{fancyhdr,refcount}
\usepackage{lastpage}% http://ctan.org/pkg/lastpage
\fancyhf{}% Clear header/footer
\renewcommand{\headrulewidth}{0pt}% No header rule

First page.


Last page.

If you're running into problems with unprocessed floats at the end of the document, one might have to consider using atveryend.

  • I like the refcount package.
    – StrongBad
    Nov 4, 2013 at 8:33

The problem is that the page counter is incremented at every call of the output routine and there is at least a call of it when TeX decides the document has ended. So totcount is unreliable with page.

You can use zref-lastpage for this purpose, because it provides expandable access to the referenced value.


      \thepage\ of\ \zref@extract{LastPage}{page}%


% uncommenting the following lines will show page numbers as “1 of 2” and “2 of 2”
% \clearpage
% y

  • I feel silly now. Of course you cannot use totcount with page, otherwise there would be no need for packages like lastpage. Thank you for seeing around my question and realizing that my problem was accessing the reference value.
    – StrongBad
    Nov 4, 2013 at 8:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .