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!

2 Answers2

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}
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}
Schweinebacke
  • 26,336
  • 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