Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

If I have a page count of 7, but the last page is a grading sheet (using the exam class). I do not actually want it to be counted as part of the exam, although I need one copy per printout. The variable \numpagescontains the number 7, but I want to make it 6, such that the students read Side 1 of 6 etc. in the footer. Is there a way to make a formula that does something like:

\renewcommand{\numpages}{\numpages - 1}

?

Most questions involving page numbers seem to simply reset the counter after a few pages (using \setcounter{page}{1}), such that there is a new page one. In this case, that would not work.

share|improve this question
1  
Can you not just put a label on the sixth page and then use \ref to get the page number as the page count? This is basically what the lastpage package does automatically for the last page. You just need to put your label on the last page you want counted and to use that in place of \numpages. I think that would be a lot simpler than trying to use \numpages minus whatever. (What if your grading sheet spills to a second page? Then you'll need to adjust the definition manually.) –  cfr Jan 9 at 1:59
    
Did you try out packages like lastpage or the more advanced pageslts? –  Speravir Jan 9 at 3:31
    
Oh I forgot: In documentation for pageslts there’s a section “Alternatives”, that you should read. Some of the packages look promising. –  Speravir Jan 9 at 3:40
add comment

2 Answers

up vote 5 down vote accepted

\numpages in the exam document class is defined as

\def\numpages{\@ifundefined{exam@lastpage}%
  {\mbox{\normalfont\bf ??}}%
  \exam@lastpage
}% numpages

So, one could redefine it as follows

\def\numpages{\@ifundefined{exam@lastpage}%
  {\mbox{\normalfont\bf ??}}%
  \the\numexpr\exam@lastpage-1\relax
}% numpages

Note that this redefinition requires the use of a \makeatletter...\makeatother pair. See What do \makeatletter and \makeatother do?

share|improve this answer
add comment

Something like this:

\documentclass{article}
\begin{document}
    Page \pageref{pg:one} of the exam\label{pg:one}.

    There are \pageref{pg:examend} pages in this examination.
    \clearpage
    Page \pageref{pg:two} of the exam\label{pg:two}.
    \clearpage
    Page \pageref{pg:three} of the exam\label{pg:three}.
    \clearpage
    Page \pageref{pg:four} of the exam\label{pg:four}.
    \clearpage
    Page \pageref{pg:five} of the exam\label{pg:five}.
    \clearpage
    Page \pageref{pg:six} of the exam\label{pg:six}.
    \label{pg:examend}
    \clearpage
    Page \pageref{pg:seven} contains answers\label{pg:seven}.
\end{document}

page 1 stating total page count for exam page 7 is not counted

Please note that I cannot check these images have uploaded correctly as I am unable to view images on the site at the present time.

EDIT: Since you are using the exam class and want to use \numpages, you could adapt the example from the manual of headers and footers to use this as follows:

\documentclass{exam}

\pagestyle{headandfoot}
\runningheadrule
\firstpageheader{Math 115}{First Exam}{July 4, 1776}
\runningheader{Math 115}
{First Exam, Page \thepage\ of \numpages}
{July 4, 1776}
\firstpagefooter{}{}{}
\runningfooter{}{}{}

\def\numpages{%
  \pageref{pg:examend}
}% numpages

\begin{document}
    Put your exam questions here.
    \clearpage
    Some more questions here.
    \label{pg:examend}
    \clearpage
    Put the answers here.
\end{document}

The only oddity is that this will give e.g. "Page 3 of 2" on the final page which has the answers. You could avoid that if you liked by redefining the header command at the end of the exam.

share|improve this answer
    
+1 Thanks for your effort, but I am not looking for a solution which hardcodes page numbers. –  macmadness86 Jan 9 at 2:16
    
@macmadness86 I don't think I'll be any help then, I'm afraid. To be honest, I don't even understand what you mean. If you want to hardcode the page numbers, why not just write '6'? –  cfr Jan 9 at 2:57
2  
@macmadness86: Using references does not mean that things are hard-coded. –  Werner Jan 9 at 4:02
    
@cfr I mean that adding \pageref all over the place is not what I had in mind. This is what I mean by "hardcoded"—writing extra code on every page. Consider an exam with 100 questions taking up many pages. Your method would require much more work than the solution provided by Werner, for example. I knew some redefinition of the numpages would be best, but my skills in this area are limited. This way, the body of my document remains untouched, yet my goal achieved! Thanks, both of you! –  macmadness86 Jan 9 at 12:03
1  
@macmadness86 I only put those there to demonstrate the idea. I was assuming that you would just include it where necessary e.g. in the definition of your page footer/header or at the beginning of the exam or whatever. If you wanted it on every page, I'd assume that would be as part of a header/footer and you'd just write that once. Since you didn't give a MWE, I had no idea where you wanted to use it so I just did something to show the number was available everywhere. –  cfr Jan 9 at 22:29
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.