You are redefining the builtin \thepage
-command, which is not good! If any other package use it (as you demonstrate e.g. LastPage) it will be affected by this. Also It has no purpose for the header on the last page when you have \thispagestyle{empty}
.
I assume you do not want the back cover to count as the last page.
LastPage puts the current page number into a macro called \lastpage@lastpage
. To achieve the (presumably) desired effect you could combine this with \number\numexpr
. So you'd do \rhead{\thepage~of~\the\numexpr\lastpage@lastpage-1\relax}
.
Furthermore, it seems that you might want to have the text "Back Cover" on the top right part of the back cover. In this case,
you could just redefine \rhead
instead of \thepage
.
All in all:
\documentclass{article}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\makeatletter
% ^so we can use \macros containing @ in their macronames
% Just remove the -1 below if you did not want to subtract 1
\rhead{\thepage~of~\the\numexpr\lastpage@lastpage-1\relax}
\makeatother
\begin{document}
Page 1\clearpage Page 2\clearpage
% Switch out the line below with \rhead{Back Cover} if you want "Back Cover" in your header
\thispagestyle{empty}
\centering
~\vfill
\huge{[This page is intentionally left blank.]
\vfill
\end{document}
\rhead
andLastPage
are not part of LaTeX. (At least two packages define LastPage and various classes/packages define\rhead
. These definitions are not equivalent.) Why don't you provide an MWE? – cfr May 30 '18 at 4:01