I'm trying to find a way to stop the page count in my report. So the count stops, then it comes to the appendix. Then have a separate count for the appendix, with the footer also changing so when the appendix starts, the page count says (e.g.) Page 1 of 12 pages.
-
possible duplicate of Different page numbering in appendix?– JakeCommented May 29, 2012 at 21:26
-
@Jake The linked question is not about adding one or several "LastPage" counters.– lockstepCommented May 29, 2012 at 21:30
-
Yeah, you're right. It probably should have been more of a "Have you looked at (...) yet? Maybe you could show what you've tried so far." comment. So much for duplicate-hunting badges =)– JakeCommented May 29, 2012 at 21:31
3 Answers
If you're after a hyperref
-compatible version, you could fool TeX and use a different representation of the page counter for the appendix.
The MWE below uses apppage
as the replacement representation at the start of the appendix via the following redefinition:
\renewcommand{\thepage}{\arabic{apppage}}
This allows the regular page counter to still continue as usual and therefore "keep hyperref
happy." Here's an entire example:
\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{fancyhdr}% http://ctan.org/pkg/fancyhdr
\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\newcounter{apppage}
\fancyhf{}% Clear fancy header/footer
\fancyfoot[C]{Page~\thepage~of~\pageref{lastpage}}
\pagestyle{fancy}
\begin{document}
See~\pageref{applastpage} for the last page of the appendix.
\section{First section}\lipsum[1-4]
\section{Second section}\lipsum[5-8]
\section{Last section}\lipsum[9-12]
\label{lastpage}
\clearpage\appendix
\renewcommand{\thepage}{\arabic{apppage}}
\fancyfoot[C]{Page~\thepage~of~\pageref{applastpage}}
\pagenumbering{arabic}
\section{First appendix}\lipsum[1-4]
\section{Second appendix}\lipsum[5-8]
\section{Last appendix}\lipsum[9-12]
\label{applastpage}
\end{document}
I've used lastpage
as a basic label for the last page just as an illustration. For the last page of appendix and label applastpage
, it would be better to use the lastpage
package's LastPage
label, or even the pageslts
package's VeryLastPage
label.
-
For some reason. It's only saying Page 3 of 19 Pages. Even so that the report that is 54 pages Commented Jun 3, 2012 at 0:26
-
@mortenstarck: You'd have to supply more information than that, since I can't seem to replicate that problem using my minimal example above. That is, it works fine for me showing the correct page numbers in the footer. On a side note: if you wish to remove the hyperlink in the footer, use
\pageref*
.– Werner ♦Commented Jun 3, 2012 at 0:45 -
This is the main document dl.dropbox.com/u/2230967/The%20SOMA%20Project.tex . I no it's a little messy. Commented Jun 3, 2012 at 0:55
-
@mortenstarck: There are so many other files missing that (most likely) includes necessary stuff that I'm unable to compile this. For example, are you including a
\label
on the last page, or are you using theLastPage
label fromlastpage
? It's obvious that you're including the package, but your footer still refers to\pageref*{applastpage}
and not\pageref*{LastPage}
. How about including a bunch of\lipsum
s to make up for all the other files and have something that I can compile. Then I'll look at it again.– Werner ♦Commented Jun 3, 2012 at 1:35 -
If you would use a prefix or roman numbers in appendix,
\usepackage{pageslts} \lastpageref{LastPages}
would be helpful Commented Nov 27, 2021 at 11:07
Here's a solution in case you also want a "lastpage" counter for the main part of your document. Notes:
I have used the
etoolbox
package to prepend code to the\appendix
command -- this way, the document body does contain only "semantic markup" and no internal redefinitions.Although
report
uses theoneside
andopenany
class options, my redefinition also gives correct page numbering fortwoside
/openright
.The
emptypage
package will prevent displays like "Page 4 of 3" on an otherwise blank last page of the main part of your document.
\documentclass{report}
\usepackage{lastpage}
\usepackage{emptypage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot[C]{Page~\thepage\ of~\pageref{LastMainPage}}
\fancypagestyle{plain}{%
\fancyhf{}%
\renewcommand{\headrulewidth}{0pt}%
\fancyfoot[C]{Page~\thepage\ of~\pageref{LastMainPage}}%
}
\usepackage{etoolbox}
\preto{\appendix}{%
\label{LastMainPage}%
\ifbool{@openright}{%
\cleardoublepage
}{%
\clearpage
}%
\pagenumbering{arabic}%
\fancyfoot[C]{Page~\thepage\ of~\pageref{LastPage}}%
\fancypagestyle{plain}{%
\fancyhf{}%
\renewcommand{\headrulewidth}{0pt}%
\fancyfoot[C]{Page~\thepage\ of~\pageref{LastPage}}%
}%
}
\usepackage{lipsum}
\begin{document}
\chapter{First}
\lipsum[1-12]
\appendix
\chapter{App-First}
\lipsum[1-8]
\end{document}
Here's a simple solution
\documentclass{report}
\usepackage{lastpage}
\usepackage{fancyhdr}
\usepackage{kantlipsum} % dummy text
\begin{document}
\chapter{abc}
\kant
\cleardoublepage
\appendix
\pagenumbering{arabic}
\fancypagestyle{plain}{\fancyhf{}
\renewcommand\headrulewidth{0pt}\fancyfoot[C]{\thepage\ of \pageref{LastPage}}}
\pagestyle{plain}
\chapter{app}
\kant
\end{document}
Pages in the appendix will have "1 of 3" in the footer. You can customize at will. However, this won't please hyperref
.