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.

The user inputs the start serial number and the number of pages. Then that serial number needs to be printed on top of every page, auto incremental for each page. The final output may be a multipage PDF file. Is it possible to do it with pdfLaTeX? I have been using LaTeX for long but do not know if this requirement can be programmed. As a next step I would like to encode the serial number as a barcode. I think the later requirement will be easier to fulfill.

share|improve this question
you don't say whether you want page numbers as well. if not, it becomes simple (page numbers are autoincremented anyway) so you start by setting the page to your start serial number. –  wasteofspace Oct 27 '11 at 9:22
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. –  egreg Oct 27 '11 at 11:14
add comment

1 Answer

You can simply define an initial value and add the page number to it. That would look like this, placing the serial number in the top right corner using fancyhdr.


lipsum is used to generate a couple of pages of text to demonstrate the principle. You should initiate \snuminit to your initial value minus the initial page number.

EDIT updated the answer to reflect Ulrike Fischer's comments. Also note that this might cause problems if you don't want the serial numbers to increase in the same fashion as the page numbers. For instance, when you number the main matter separately from the front matter.

share|improve this answer
Don't use \arabic and \thepage in places where you need a real number. Both commands are often redefined (\arabic e.g. by the hebrew language, \thepage can give a roman number). Use \number\value{snuminit}. Or don't use an extra counter at all but e.g. \newcommand\startserialnumber{42} \the\numexpr\startserialnumber + \number\value{page}\relax –  Ulrike Fischer Oct 27 '11 at 10:02
Good points. Also makes me wonder if this is a good approach at all. Often front amtter is numbered in roman indeed, afaik thepage reverts to 1 after that. So if you have serial numbers on the front matter as well, you would get duplicate serial numbers in the main matter. –  Roelof Spijker Oct 27 '11 at 10:08
I only commented about the technical aspect to set counters. I didn't understand which numbering scheme the OP wants so I don't know if your solution is adequate. –  Ulrike Fischer Oct 27 '11 at 10:10
I've modified my answer to incorporate your comment. As for the numbering scheme, perhaps @Galaxy could elaborate on what he hopes to achieve. –  Roelof Spijker Oct 27 '11 at 10:25
Using ctan.org/pkg/everyshi package \EveryShipout the \snuminit content could be increased by 1. In this way one would be independent of the pagenumbering. –  Stephen Oct 27 '11 at 18:02
add comment

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.