I want to get the following header:
Left page: \thepage\hfill\chaptername{}\thechapter
Right page: \chaptername\hfill\thepage
So I write:
\documentclass{book}
\usepackage{fontspec} % enagles loading of OpenType fonts
\usepackage{polyglossia} % support for languages
% fonts:
\defaultfontfeatures{Scale=MatchLowercase,Mapping=tex-text} % without this XeLaTeX won't turn "--" into dashes
\setmainfont{Arial}
\setsansfont{Arial}
\setromanfont{Arial}
\setmonofont{DejaVu Sans Mono}
\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[LO]{\thechapter}
\fancyhead[RE]{\chaptername}
\fancyhead[LE,RO]{\thepage}
\pagestyle{fancy}
\begin{document}
\chapter{foo}
Foo!
\chapter{bar}
Bar!
\chapter{baz}
Baz!
\end{document}
but it doesn't print chapter name in header. What do I do wrong?
Edit:
Current best bet:
\documentclass{book}
\usepackage{fontspec} % enagles loading of OpenType fonts
\usepackage{polyglossia} % support for languages
% fonts:
\defaultfontfeatures{Scale=MatchLowercase,Mapping=tex-text} % without this XeLaTeX won't turn "--" into dashes
\setmainfont{Arial}
\setsansfont{Arial}
\setromanfont{Arial}
\setmonofont{DejaVu Sans Mono}
\usepackage{fancyhdr}
\renewcommand{\rightmark}[1]{\markboth{#1}{}}
\renewcommand{\leftmark}[1]{\chaptername{}\thechapter}
\fancyhf{}
\fancyhead[LO]{\leftmark}
\fancyhead[RE]{\rightmark}
\fancyhead[LE,RO]{\thepage}
\pagestyle{fancy}
\begin{document}
\chapter{foo}
Foo!
\chapter{bar}
Bar!
\chapter{baz}
Baz!
\end{document}
Best Answer
This does what you specify:
Note that
\pagestyle{fancy}
must go before the redefinitions of the headers and of\chaptermark
. The current chapter title is available as\leftmark
which mustn't be redefined.