0

I would like to have an A prefix in appendix page numbering, but not in appendix page count.

No prefix in page count

A MWE inspired be this answer.

\documentclass[a4paper,12pt,bibliography=totoc]{scrartcl}
\usepackage{blindtext}
\usepackage{graphicx} 
%\usepackage{pageslts} % mixes up the page numbering in the appendix
\pagenumbering{arabic} % page count in the body


%%%%%%%%%%
\begin{document}

\section{Section 1}

\textbf{Number of pages:}
\begin{itemize}
    \item \pageref{lastpage} pages in the body
    \item \pageref{applastpage} pages in appendix
\end{itemize}


\section{Section 2}

\Blindtext

\label{lastpage} % page count

\clearpage
\appendix
\counterwithin{figure}{section}
\pagenumbering{arabic} % page count
\renewcommand{\thepage}{A.\arabic{page}} % adds prefix to page numbering

\section{Appendix}\label{appendix}

\blindtext 

\label{applastpage} % page count
\end{document}

P.S. See also a related question in here (these were originally in the same post, but decided to differentiate them for clarity.)

1 Answer 1

1

There are two ways to do this. First, you can use \getpagerefnumber and \StrBehind to remove A. etc.

\documentclass[a4paper,12pt,bibliography=totoc]{scrartcl}
\usepackage{blindtext}
\usepackage{graphicx} 
%\usepackage{pageslts} % mixes up the page numbering in the appendix
\pagenumbering{arabic} % page count in the body

\usepackage{refcount}
\usepackage{xstring}

\AtBeginDocument{%
  \edef\lastpageA{\getpagerefnumber{applastpage}}%
  \StrBehind{\lastpageA}{.}[\lastpageB]%
}

%%%%%%%%%%
\begin{document}

\section{Section 1}

\textbf{Number of pages:}
\begin{itemize}
    \item \pageref{lastpage} pages in the body
    \item {\lastpageB} pages in appendix
\end{itemize}


\section{Section 2}

\Blindtext

\label{lastpage} % page count

\clearpage
\appendix
\counterwithin{figure}{section}
\pagenumbering{arabic} % page count
\renewcommand{\thepage}{A.\arabic{page}} % adds prefix to page numbering

\section{Appendix}\label{appendix}

\blindtext 

\label{applastpage} % page count
\end{document}

The second way is to save \arabic{page} in the \label (using \ref, not \pageref)

\documentclass[a4paper,12pt,bibliography=totoc]{scrartcl}
\usepackage{blindtext}
\usepackage{graphicx} 
%\usepackage{pageslts} % mixes up the page numbering in the appendix
\pagenumbering{arabic} % page count in the body

\makeatletter
\newcommand{\savepage}[1]{% #1 = label name for page counter
  \edef\@currentlabel{\arabic{page}}%
  \label{#1}}
\makeatother

%%%%%%%%%%
\begin{document}

\section{Section 1}

\textbf{Number of pages:}
\begin{itemize}
    \item \ref{lastpage} pages in the body
    \item \ref{applastpage} pages in appendix
\end{itemize}


\section{Section 2}

\Blindtext

\savepage{lastpage} % page count

\clearpage
\appendix
\counterwithin{figure}{section}
\pagenumbering{arabic} % page count
\renewcommand{\thepage}{A.\arabic{page}} % adds prefix to page numbering

\section{Appendix}\label{appendix}

\blindtext 

\savepage{applastpage} % page count
\end{document}
1
  • I found the second way especially straightforward. Since I am using hyperref, I just added and asterisk to disable the links (\ref*{lastpage}) Commented Nov 28, 2021 at 1:43

You must log in to answer this question.

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