This question is similar to: How do I have two sets of page numbers in a document?
I have an exam
class document (built on article
) that contains the exam questions in a first section*
and extra output/figures in a second section*
. Both are in the same document in order to be able to refer to the correct labels using ref{}
. Yet, both sections will be printed separately and should contain page numbers like page 3 of 12
.
I use fancyhdr
to get that footer correctly, but I have a problem getting the correct numpages
. Now it counts only the number of pages for the last section (in this case 2). I've been playing with the solution given in the question I link to, but I was hoping there was a simpler solution.
Example :
\documentclass{exam}
\renewcommand{\maketitle}{
% Get rid of verticalmode errors from exam class
}
% From the cls file we use for the exams
\AtBeginDocument{
\pagestyle{foot}
\footer{}{Page \thepage\ / \numpages}{}
}
\usepackage{kantlipsum} % get some text
\begin{document}
You have \numpages~pages
\kant[1-14]
\clearpage
\setcounter{page}{1}
\section*{Another section}
You have \numpages~pages
\kant[1-7]
\end{document}
Best Answer
Easier to show then explain.
\label
stores the counter and page from the last\refstepcounter
, hence the dummy counter. There are other ways to do this, but they involve\makeatletter
...\makeatother
.You can't mess with
\numpages
, but you can create a new macro (\secpages
) to replace it.