2

I am using fancyhdr and lastpage. I want to write a Bachlorthesis and the last page must be the statutory declaration wich should not be part of the page count. But this page is counted in LastPage. How can i get lastpage to not count this page ?

\setcounter{page}{\pageref*{LastPage}-1} is what i am looking for

\documentclass[a4paper]{report}

\usepackage{fancyhdr}
\usepackage{lastpage}

\pagestyle{fancy}
\fancypagestyle{plain}{}
\fancyhead[RO,RE]{Page \thepage\ of \pageref*{LastPage}}
\fancyhead[LO,LE]{\leftmark}

\begin{document}

% much content

% now the last page:
\thispagestyle{empty}
% content of the declaration
  • 3
    just put your own \label{zzz} on to the last page you want to count, and use \pageref{zzz} – David Carlisle Jul 13 '15 at 11:19
3

You can use the zref package and decrease the generated number by 1.

\documentclass[a4paper,twoside]{report}

\usepackage{fancyhdr}
\usepackage[lastpage]{zref}

\usepackage{kantlipsum}

\makeatletter
\newcommand{\reallastpage}{%
  \the\numexpr\zref@extractdefault{LastPage}{page}{0}-1\relax
}
\makeatother
\pagestyle{fancy}
\fancypagestyle{plain}{}
\fancyhead[RO,RE]{Page \thepage\ of \reallastpage}
\fancyhead[LO,LE]{\leftmark}

\begin{document}

\kant

% now the last page:

\clearpage
\thispagestyle{empty}

{\Large Declaration}

\kant[1]

\end{document}

enter image description here

As you can see, the declaration page is number 4.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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