# Missing chapter name when using fancyhdr

I want to get the following header:

Left page: \thepage\hfill\chaptername{}\thechapter

Right page: \chaptername\hfill\thepage

So I write:

\documentclass{book}

\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{}
\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{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{}
\pagestyle{fancy}

\begin{document}

\chapter{foo}

Foo!

\chapter{bar}

Bar!

\chapter{baz}

Baz!

\end{document}

-
\chaptername doesn't refer to the chapter title, it produces the word "Chapter" (possibly translated). You probably want \leftmark, instead. –  egreg Feb 18 '13 at 17:51
I guess it should be \fancyhead[RE]{\thechapter} and \fancyhead[LO]{\chaptername}, no ? –  Corentin Feb 18 '13 at 17:52
Nope. Only \thepage. I know there are subtleties like \chaptermark and \rightmark -- but I though it should be working this crude way also. –  Adobe Feb 18 '13 at 17:53
@egreg: \renewcommand{\chaptermark}[1]{\markboth{#1}{}} with \fancyhead[RE]{\chaptermark} doesn't work either. –  Adobe Feb 18 '13 at 17:55
@Corentin: I'll fix it. –  Adobe Feb 18 '13 at 17:56

This does what you specify:

\documentclass{book}

\usepackage{polyglossia} % support for languages
\usepackage{kantlipsum} % for mock text in the example

% fonts:
\defaultfontfeatures{Scale=MatchLowercase,Ligatures=TeX} % without this XeLaTeX won't turn "--" into dashes
\setmainfont{Arial}
\setsansfont{Arial}
\setmonofont{DejaVu Sans Mono}

\usepackage{fancyhdr}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhf{}

\begin{document}

\chapter{foo}

\kant

\chapter{bar}

\kant

\end{document}


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.

-
Cool. I find that sometimes that order thing is a little bit unclear. How do I know that fancyhf{} redefines chaptermark for example. –  Adobe Feb 18 '13 at 18:17
@Adobe There's plenty of examples in the documentation of fancyhdr. It's \pagestyle{fancy} that does the redefinition, by the way. Last, I repeat: don't use \setromanfont. –  egreg Feb 18 '13 at 18:21
Ok: \setdefaultlanguage is deprecated in favour of \setmainlanguage, and \setromanfont is deprecated in favour of \setmainfont`. –  Adobe Feb 18 '13 at 18:36