附录前缀位于页码中,但不位于页数中

附录前缀位于页码中,但不位于页数中

我希望A附录页码中有一个前缀,但不要在附录页数中添加前缀。

页数无前缀

MWE 的启发 回答。

\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}

PS 另请参阅相关问题这里(这些原本是在同一篇文章中,但为了清楚起见决定区分它们。)

答案1

有两种方法可以做到这一点。首先,您可以使用\getpagerefnumber\StrBehind删除A.等。

\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}

第二种方法是保存\arabic{page}\label(使用\ref,而不是\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}

相关内容