3

I am using the fancyhdr package and I have got big issues with the page numbering. Indeed, the pages appear for each new title, but then I don't have anymore page numbers, Here is the code furnish by the package, I hope that someone could explain me what is wrong:

\usepackage{fancyhdr}
\lhead[\rm\thepage]{\fancyplain{}{\sl{\rightmark}}}
\rhead[\fancyplain{}{\sl{\leftmark}}]{\rm\thepage}
\chead{}
\lfoot{}
\rfoot{}
\cfoot{}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\btypeout{\thechapter\space #1}\markboth{\@chapapp\ \thechapter\ #1}{\@chapapp\ \thechapter\ #1}}  
\renewcommand{\sectionmark}[1]{} \renewcommand{\subsectionmark}[1]{} \def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else \hbox{} \thispagestyle{empty}
\newpage
\if@twocolumn\hbox{}
\newpage\fi\fi\fi}
jub0bs
  • 58,916
Ludovic
  • 31

1 Answers1

1

This code, which is more efficient and maintainable than yours by using the "modern" syntax of fancyhdr works as intended (or as I interpret your code).

\documentclass{book}

\usepackage{fancyhdr}
\usepackage{emptypage}  % avoids the need to redefine \cleardoublepage
\usepackage{kantlipsum} % to provide mock text for the example

%%% set up the headers
\pagestyle{fancy}
\fancyhf{} % clear all fields
\fancyhead[RO,LE]{\thepage} % the page number goes on the outer part
\fancyhead[LO,RE]{\slshape\leftmark} % the chapter title in the inner part

%% change how \chaptermark sets the marks
\makeatletter % we need to use \@chapapp
\renewcommand{\chaptermark}[1]{%
  \typeout{\thechapter\space #1}%
  \markboth{\@chapapp\ \thechapter\ #1}{}}
\makeatother
\renewcommand{\sectionmark}[1]{}
%\renewcommand{\subsectionmark}[1]{} % useless

\begin{document}

\mainmatter

\chapter{Xyz}
\kant[1-30]

\chapter{A new one}
\kant[31-60]

\end{document}
egreg
  • 1,121,712
  • Thank you for your answer, I have checked, maybe I have made a mistake in my code... I am going to make tests... – Ludovic May 26 '13 at 13:26
  • This line was missing:\lhead{Chapter 3. \emph{Chapter_title}} Thank you very much! – Ludovic May 26 '13 at 13:46
  • Are you issuing a \lhead command for every chapter? If so, you're misusing LaTeX and fancyhdr. – egreg May 26 '13 at 13:51