17

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?

Masroor
  • 17,842
Tim
  • 5,763
  • I hope you don't insist to use \pagestyle{plain} and still want to get the desired result. Please see the solution below. – Masroor Jan 01 '14 at 01:19

1 Answers1

27

Solution Idea

  1. Use package lastpage to define the label LastPage, allowing us to refer to the last page via \pageref{LastPage}.

  2. Use fancyhdr to 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

enter image description here

Further Tweaking

  1. 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.

  2. Use of fancyhdr actually 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
  • 2
    Right 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