# page numbers should be of the form 4/7 [duplicate]

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?

-

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

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

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.

\documentclass{article}
\usepackage{lipsum,lastpage}  % 'lipsum' provides filler text
\makeatletter
\renewcommand{\@oddfoot}{\hfil \thepage/\pageref{LastPage} \hfil}
\makeatother
\begin{document}
\lipsum[1-15]
\end{document}


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.

-
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