TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am making a questionnaire, to be filled out with pen and paper. I need 40 copies of it, with around 13 pages each. I expect that some participants might take the questionnaire apart, so I have to be able to match the pages from an exemplar to each other. I want to do it in a simple way, by printing a number from 1 to 40 in the footer of each copy.

However, I don't know how to generate different copies from the same TeX source, and I don't want to manually compile 40 times, changing the number each time. I decided to put everything between \begin{document} and \end{document} in a \foreach loop from pgffor, using a counter to print the number in the footer. This produces the 40 copies I need in a single document (not a problem from my point of view), but of course, this changes the page numbering, so the second exemplar starts at page 14 instead of page 1. As the page number is printed in the footer too, this is unacceptable.

Because I am still making some changes to the questionnaire, I might suddenly find myself with 12 or 14 pages. So, taking the page number modulo 13 for printing in the footer is a bad idea.

Any ideas how to make this work? Or will I have to fall back to the hardcoded modulo and just manually change the number if needed? I will prefer it to be really from inside LaTeX, not a script which changes the number in the .tex file and recompiles (I have to compile on different OSes). I don't care if I end up with one very long .pdf or forty small ones, as long as it isn't the same .pdf overwritten forty times.



\fancyfoot[C]{Questionnaire \arabic{questionnaireNr}} 
\fancyfoot[R]{page \thepage}

    \foreach \x in {1,2,3,...40} 

        Lorem Ipsum %here are the questions 
share|improve this question
up vote 8 down vote accepted

In the start of your \foreach, add


This resets the page counter to 1 when the loop is run. (I am assuming you want each new copy to start on a new page.)

share|improve this answer

I have had the same problem, and came up with the following solution. The enclosed LaTeX input takes a given PDF file (= one copy of the questionnaire) and creates N copies, each numbered 000..N. The number is added in light grey to the lower right corner. Feel free to customize as you like.

% Print an exam N times, with serial numbers 000...N
% by Andreas Zeller, Saarland University



% What is the starting number?

% How many exams do we need?

% Which is the input PDF file?

% This is to control the placement of the number.  
% I am using A4 format, so feel free to adapt to your page size.
\textwidth  16cm
\textheight 23cm

% We use headers to output the serial number
\renewcommand{\headrulewidth}{0pt} % No header line
\renewcommand{\footrulewidth}{0pt} % No footer line

% Actual command to include the serial number
% Some number padding - for up to 999 exams
\ifnum\numberexam<100 0\fi%
\ifnum\numberexam<10 0\fi%

% And here comes the single loop across all documents
% pagecommand by itself adds nothing, 
% but causes our new headers and footers to be printed

Enjoy! -- Andreas

share|improve this answer

Your Answer


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.