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

Possible Duplicate:
How can I add “page # of ##” on my document?

While submitting Test paper in LaTeX, I was asked to display page numbers as current page number out of total page numbers.

I am using article class.

For example it should look like: 1 out of 4, 2 out of 4, 3 out of 4 etc. or 1/4,2/4 etc.

How to obtain it?

share|improve this question

marked as duplicate by Marco Daniel, Jake, Martin Scharrer Apr 15 '12 at 13:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Have a look at How can I add “page # of ##” on my document?. – Stefan Kottwitz Apr 15 '12 at 13:01
up vote 8 down vote accepted

You could simply use the lastpage package and use the following MWE to get the 1/3, 2/3, etc "look". If you want "out of" instead of "/", just replace \thepage/\pageref{LastPage} with \thepage\ out of \pageref{LastPage}. Be sure to compile the document twice to give LaTeX a chance to get the cross-referencing right.

Note that the code in the MWE doesn't require you to use any additional packages (such as fancyhdr) to manipulate the page headers and footers.

\usepackage{lipsum,lastpage}  % 'lipsum' provides filler text
\renewcommand{\@oddfoot}{\hfil \thepage/\pageref{LastPage} \hfil}

Addendum: Should you be using the hyperref package as well, you may want to replace the instruction \pageref with \pageref*. The former command would instruct hyperref to make its argument into a hyperlink -- probably not an intended effect. The hyperref package provides the variant command \pageref* (as well as \ref* ...) to avoid creating hyperlinks out of the cross-reference.

share|improve this answer
It worked perfectly! – manjusha Apr 15 '12 at 13:28
This does not work with the first page ... – Hesam Apr 8 '13 at 6:52
@Hesam - May I ask you to be a bit more specific as to what doesn't work on the first page? Do you get an incorrect page number, or no "1 of nn" page marker, or is there another problem? – Mico Apr 8 '13 at 11:22
I only get "1", no "1 of X". It appears once you add \maketitle ... – Hesam Apr 9 '13 at 7:30
@Hesam - Are you working with example code given in my answer, or are you working with your own document class and document setup? The reason I ask is that it looks like your document class is setting the page style of the title page separately from that of the other pages -- in which case my answer won't apply. – Mico Apr 9 '13 at 8:54

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