[Tex/LaTex] How to have two sets of page numbers in a document

lastpagepage-numbering

I want to have two sets of page numbers (P and p) in my document. The first one (P) is global, the second one (p) resets to 1 at some predefined points.

So, the document will look like,

Text

P1/5 p1/3

Text

P2/5 p2/3

Text

P3/5 p3/3

Text. In this page the page number (p, second one) is reset.

P4/5 p1/2

Text

P5/5 p2/2

To get the total page count a label in the last page or the lastpage package (http://www.ctan.org/pkg/lastpage) can help me. And that is not the subject of this question.

The problem is with the second counter. I can use chappg (http://www.ctan.org/pkg/chappg) with noauto option. But I loose the global page counter P. Moreover, the (sub) total number of pages in that group has to be manually set.

I understand that if I write a set of macros with a new counter (my@local@page), reset it at my predefined points, label the last page in a group (label names will have to be distinct), perhaps I can achieve my goal. But that requires at least half a day. Which I do not have at this moment.

I was wondering if you can suggest something readily usable.

Best Answer

Here's a possible setup. I use fancyhdr for typesetting the two page numbers and also for stepping the secondary counter. The macro \resetpageaux does a \clearpage, sets a label and sets the secondary counter to zero. At the end of the document we set also the last label.

\documentclass{article}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyhf{}
\fancyfoot[C]{\twopagenumbers}
\fancypagestyle{plain}{
  \renewcommand{\headrulewidth}{0pt}
  \fancyhf{}
  \fancyfoot[C]{\twopagenumbers}
}

\usepackage{atenddvi}
\usepackage[user]{zref}

\newcounter{pageaux}
\def\currentauxref{PAGEAUX1}
\newcommand{\twopagenumbers}{%
  \stepcounter{pageaux}%
  P \thepage/\zpageref{LastPage} -- p \thepageaux/\ref{\currentauxref}%
}
\makeatletter
\newcommand{\resetpageaux}{%
  \clearpage
  \edef\@currentlabel{\thepageaux}\label{\currentauxref}%
  \xdef\currentauxref{PAGEAUX\thepage}%
  \setcounter{pageaux}{0}}
\AtEndDvi{\edef\@currentlabel{\thepageaux}\label{\currentauxref}}
\makeatletter

\usepackage{kantlipsum} % just for mock text

\begin{document}

\kant

\resetpageaux

\kant[1-14]

\resetpageaux

\kant[1-22]

\end{document}

enter image description here

Related Question