1

This is related to How to use \pageref{foo} as a number? but slightly different:

\documentclass{scrreprt}
\usepackage{blindtext}
\renewcommand*\thepage{A\arabic{page}}
%This type of pagenumbering is required by the customer
\begin{document}
  This document consist of \pageref{LastPage} pages.\\  
  %Needed in this case: "This document consist of 4 pages."
  %(Length of document varies each time of course)
  \blindtext[15]
  \label{LastPage}
\end{document}

I need a way to convert e.g. "A4" into "4" without breaking the format of the pagenumbering in the document. I tried to use \StrSubstitute but it failed, because it does attempt to replace something in the \pageref command instead doing the operation with its value "A4". I also tried every proposed solution in How to use \pageref{foo} as a number? but without success.

How would you tackle this problem? I don't seem to understand correctly how to read the value from \pageref and work with it (i.e. eliminate the "A" with \StrSubstitute).

Any help would be greatly appreciated. Thanks a lot!

  • 1
    easiest is to use the lastpage package which makes a special internal \label on the past page that always uses a numeric form even if \thepage is unsuitable – David Carlisle Jan 16 '17 at 14:11
  • Unfortunately this does not work. It gives me "This document consist of A4 pages." – Martin Brennecke Jan 16 '17 at 14:25
1

With the totpages package:

\documentclass{scrreprt}
\usepackage{blindtext}
\renewcommand*\thepage{A\arabic{page}}

\usepackage{totpages}
%This type of pagenumbering is required by the customer
\begin{document}
  This document consist of \ref{TotPages} pages.\\  
  %Needed in this case: "This document consist of 4 pages."
  %(Length of document varies each time of course)
  \blindtext[15]
  \label{LastPage}
\end{document}

enter image description here


To subtract the title page:

\documentclass{scrreprt}
\usepackage{blindtext}
\renewcommand*\thepage{A\arabic{page}}

\usepackage{totpages}
\begin{document}
    \addtocounter{TotPages}{-1}
  This document consist of \ref{TotPages} pages.

  \blindtext[15]
\end{document}
  • totcount does not always report the correct page counter value. The page counter is an unreliable friend! You should use an associated total counter from xassoccnt for this ;-) – user31729 Jan 16 '17 at 14:26
  • @ChristianHupfer That's "Schleichwerbung" :) – user36296 Jan 16 '17 at 14:28
  • No, it's a "Hinweis" :D – user31729 Jan 16 '17 at 14:31
  • Answer 1 works in principle. Unfortunately I forgot, that my document has a titlepage, that shall not be counted. So I am off by one page ("The document consist of 25 pages" instead of 24+title). – Martin Brennecke Jan 16 '17 at 14:35
  • @MartinBrennecke See my edit. If you need more control of what's happening, look into the xassoccnt package mentioned in Christian Hupfers comment above. – user36296 Jan 16 '17 at 14:42
1

Do not redefine \thepage but \pagemark:

\documentclass{scrreprt}
\usepackage{blindtext}
\renewcommand*{\pagemark}{\usekomafont{pagenumber}{A\thepage}}

\begin{document}
  This document consist of \pageref{LastPage} pages.

  \blindtext[15]
  \label{LastPage}
\end{document}
  • Good idea. But unfortunately this breaks my header in the original document, which is more like so: "page {\thepage} of {\pageref*{foo}}". – Martin Brennecke Jan 16 '17 at 14:53
  • @MartinBrennecke: You can/should replace \thepage by \pagemark in the document header or simply add A in front of \thepage. – Schweinebacke Jan 16 '17 at 15:04
  • Thought about that too. Decided to go by \renewcommand*\thepage{A\arabic{page}} to get a nice looking TOC like this: Inhaltsverzeichnis Anhang A – Expertenbericht Zusammenfassung . . . . . . . . . . . . . . . . . . . . . . . . A3 A-1 Prüfnachweise und weitere Dokumentation . . . . . . . A6 A-1.1 Zertifizierungsumfang . . . . . . . . . . . . . . . . . . A7 I guess this won't work with \pagemark ? – Martin Brennecke Jan 16 '17 at 16:10
  • Darn. This looks like crap without CR. But I hope you'll get the idea anyways... – Martin Brennecke Jan 16 '17 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.