1

I'm trying to put a conditional inside \cfoot from the fancyhdr package like this:

  • if the document contains a one-page there will be no footer.
  • if there are more pages the footer takes the format " \thepage of number of pages".

To set the number of pages i have used the lastpage package which provide the label LastPage allowing the user to refer to the last page of a document via \pageref{LastPage}.

When using \ifthenelse there is no problem

\documentclass{article}
\usepackage{lastpage}
\usepackage{ifthen}
\usepackage{fancyhdr}
\usepackage{lipsum}

\pagestyle{fancy}

\renewcommand{\footrulewidth}{1pt}

\cfoot{\ifthenelse{\pageref{LastPage}>1}
{Page \thepage\ of \pageref{LastPage}}{}}

\begin{document}

\lipsum

\end{document}

But with the use of \ifnum produces an error:

!Missing = inserted for \ifnum

\documentclass{article}
\usepackage{lastpage}
\usepackage{fancyhdr}
\usepackage{lipsum}
\pagestyle{fancy}

\renewcommand{\footrulewidth}{1pt}

\newcommand{\foo}{\pageref{LastPage}}

\cfoot{\ifnum\foo>1 Page \thepage\ of \pageref{LastPage}\fi}

\begin{document}

\lipsum

\end{document}

Where is the problem , with \ifnum and how to solve it ?

Salim Bou
  • 17,021
  • 2
  • 31
  • 76
  • I believe this has already been asked; anyway, you have to use \getpagerefnumber{LastPage} (with \usepackage{refcount}) and not \pageref{LastPage}. With \ifthenelse it should work the same. – egreg Apr 01 '15 at 12:09

0 Answers0