Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
\documentclass{mwrep}

%page number on the end of chapter
\makeatletter
\let\ps@closing\ps@plain
\makeatother

%margins
\usepackage{anysize}
\marginsize{3cm}{3cm}{2cm}{2cm}

\usepackage{lipsum}

%mark
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{}\chead{}\rhead{}\lfoot{}\cfoot{}\rfoot{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
%mark

\begin{document}
\chapter{AAAAAAA}
\section{aaaaaaa}
\lipsum
\section{bbbbbbb}
\lipsum
\section{ccccccc}
\lipsum
\chapter{BBBBBBB}
\section{aaaaaaa}
\lipsum
\section{bbbbbbb}
\lipsum
\section{ccccccc}
\lipsum
\chapter{CCCCCCC}
\section{aaaaaaa}
\lipsum
\section{bbbbbbb}
\lipsum
\section{ccccccc}
\lipsum
\end{document}

When you remove code between %marks, you get a number on every page. When I use fancyhdr, those settings are overwritten and page number is ommited at the beginning and the end of chapter. Is there a way to fix that? I'm only using fancyhdr to change position of page number.

share|improve this question
    
What is it that you want exactly? Page numbers on the first and last page or just on the last, or just on the first page of a chapter? –  Werner Mar 13 '12 at 23:01
    
I want page number on every page. In other words: I want the output to be exaxtly the same as if I wasn't using fancyhdr at all (except of page numer position of course). The problem is: fancyhdr overwrites my settings. –  Jan Ajan Mar 13 '12 at 23:03
add comment

1 Answer

up vote 6 down vote accepted

The mwrep class has a very peculiar way of managing page styles, so its interaction with fancyhdr might be difficult; however this seems to work:

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}\fancyfoot[R]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancypagestyle{opening}{\fancyhf{}\fancyfoot[R]{\thepage}%
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}}
\fancypagestyle{closing}{\fancyhf{}\fancyfoot[R]{\thepage}%
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}}

We simply redefine the opening and closing page styles so that they use fancyhdr way of doing the business.

Also remove the code you have regarding \ps@closing.

A solution without fancyhdr might be

\makeatletter
\def\ps@plain{%
  \let\@oddhead\@empty
  \def\@oddfoot{\reset@font\hfil\thepage}%
  \let\@evenhead\@empty
  \let\@evenfoot\@oddfoot}
\let\ps@opening=\ps@plain
\let\ps@closing=\ps@plain
\makeatother
\pagestyle{plain}

All things considered, I prefer the first solution, albeit a bit long, because it lets you customize the page style in case of needs just by using the commands provided by fancyhdr rather than going into low level commands such as \@oddfoot and so on.

share|improve this answer
    
It seems simpler to use \let\ps@closing\ps@fancy and \let\ps@opening\ps@fancy after defining the fancy page style. –  Werner Mar 13 '12 at 23:13
    
You say that mwrep may not be compatible with fancyhdr... Is there any other way to change position of page number? –  Jan Ajan Mar 13 '12 at 23:14
    
@Werner Maybe, but by defining the "fancy" page styles they are customizable in different ways. –  egreg Mar 13 '12 at 23:16
    
@egreg: Nice recovery! –  Werner Mar 13 '12 at 23:25
    
@Werner And Frank would be happier if less @ are used. –  egreg Mar 13 '12 at 23:28
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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