I am using \pagestyle{plain} to add page number to each page in its bottom. If I want something like " page number / total page number" or " page number out of total page number", how shall I do that?
Asked
Active
Viewed 4.6k times
17
1 Answers
27
Solution Idea
Use package
lastpageto define the labelLastPage, allowing us to refer to the last page via\pageref{LastPage}.Use
fancyhdrto control your footer.
The Solution
\documentclass{article}
\usepackage{lastpage}
\usepackage{fancyhdr}
\fancyfoot[C]{Page \thepage\ of \pageref{LastPage}}
% Uncomment to remove the header rule
% \renewcommand{\headrulewidth}{0pt}
\pagestyle{fancy}
\usepackage{lipsum}
\begin{document}
\lipsum[1-10]
\end{document}
The Output

Further Tweaking
If you really like it plain, perhaps you will want to use
\renewcommand{\headrulewidth}{0pt}(and may be\renewcommand{\footrulewidth}{0pt}) as well to get rid of the rules.Use of
fancyhdractually gives you a ton of other controls which should be rewarding. Please see the package documentation for further details.
Masroor
- 17,842
-
You probably want to add \renewcommand{\headrulewidth}{0pt} unless using a header. – cfr Jan 01 '14 at 01:19
-
Yes, all those tweakings are definitely possible. I left them for the end user. Please note that I did not reset the header-footer using
\fancyhf{}. That was intentional, along with the rules. – Masroor Jan 01 '14 at 01:21 -
2Right but setting \pagestyle{fancy} adds a header rule which is not present with \pagestyle{plain} so if the idea is to show a solution which just does what's asked, I guess I thought you'd nullify the rule added by changing the pagestyle. But of course you're right that the user will need to read the documentation to tweak to their liking. – cfr Jan 01 '14 at 01:31
-
@cfr Get your point and agreed upon. Added a few lines to the end of my answer. – Masroor Jan 01 '14 at 01:34
-
\footrulewidth is 0pt by default though it does no harm to show how to change it, of course. – cfr Jan 01 '14 at 01:38
-
In order to use \fancyfoot{} you need to use \pagestyle{fancy} first such that the footer could take effect. – Jason Jan 14 '20 at 00:25
-
@Jason Yes, indeed. Please note the line
\pagestyle{fancy}in my solution. – Masroor Jan 14 '20 at 04:43 -
@Masroor It's interesting that the
\pagestyle{fancy}could run after\fancyfoot{}which is a bit anti-intuitive for me from programming point of view, hence I tried to point out for other newbies like me. – Jason Jan 15 '20 at 05:36
\pagestyle{plain}and still want to get the desired result. Please see the solution below. – Masroor Jan 01 '14 at 01:19