3

How can I have alternating page numbers in the footer (using fancyhdr) in the form of (left footer) page x of y -nextpage- (right footer)page x2 of y? I now have

\pagestyle{fancy}
\cfoot{\thepage\ of \pageref{LastPage}}

But note that on the pages where the chapter starts for some reason the numbering does not apply. I am using the report class

  • When a chapter starts, pagestyle plain is used. You get to know how to redefine that one in section 7 of the fancyhdr manual. – Johannes_B Jun 14 '15 at 18:41
  • 2
    What is x2 of y then? If left page is 10 then x2 is 11? – user31729 Jun 14 '15 at 19:22
6

Something like this? The pagestyle is patched into the \chapter command, however, this must be done after \tableofcontents has been issued, otherwise, this would be applied there too.

\documentclass[twoside]{report}

\usepackage{lastpage}
\usepackage{fancyhdr}
\usepackage{blindtext}
\usepackage{xpatch}

\fancypagestyle{mystyle}{%
  \fancyhf{}%
  \fancyfoot[LE,RO]{\thepage~of \pageref{LastPage}}%
  \renewcommand{\headrulewidth}{0pt}%
}

\begin{document}
\tableofcontents

% Now patch the command
\xpatchcmd{\chapter}{%
  \thispagestyle{plain}%
}{%
  \pagestyle{mystyle}
}{}{}

\chapter{My first chapter}
\blindtext[10]

\end{document}

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.