Page Layoutfancyhdr: \chaptermark empty

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
Emanuelo
Posts: 2
Joined: Sun Apr 22, 2018 9:57 am

fancyhdr: \chaptermark empty

Post by Emanuelo »

Hi! I'm sorry if my question was asked one thousand times, but I did not found the solution by myself. In a "book" class, I want that the odd pages display in the head the name of the chapter, but not its number, nor the \chaptername.

However, if I type :

Code: Select all

Code, edit and compile here:
\documentclass[12pt,a4paper]{book}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyhead[RO,LE]{\thepage}
\fancyhead[CE]{Title of the book}
\fancyhead[CO]{\chaptermark}
\fancyfoot{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
\begin{document}
\chapter{Title of the chapter}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
And if I add enough text to reach the second odd page (the first one being "plain", as usual), after compilation (with XeLaTeX) I just see the page number shifted to le left, and that's all. No chapter title at all is displayed. I tried things like add :
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
but nothing changes. What do I wrong?

Thank you!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

fancyhdr: \chaptermark empty

Post by rais »

Hi there,
\chaptermark is used by \chpter to set the mark(s) for this chapter. If you call it from within \fancyhead, you're overwriting the current mark(s).
Use \leftmark within \fancyhead, instead.

Now, the page header on odd pages contains the chapter title (plus chapter's number & name), but not on the first page of a chapter: here, page style plain is used by default, because it lets the eye catch on a new chapter start easier, if something is missing (page header) on one page while leafing through the pages.
If you really want to change that, use \fancypagestyle{plain}{}.

Now you can use your redefinition of \chaptermark to get rid of chapter's number & name in the page header.

Put it all together:

Code: Select all

Code, edit and compile here:
\documentclass[12pt,a4paper]{book}
\usepackage{polyglossia}
\usepackage{blindtext}
\setdefaultlanguage{english}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyhead[RO,LE]{\thepage}
\fancyhead[CE]{Title of the book}
%\fancyhead[CO]{\chaptermark}<-- \chaptermark has no place here. It is used to *set* the mark(s) for a chapter, not to get it.
\fancyhead[CO]{\leftmark}
\fancyfoot{}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
\fancypagestyle{plain}{}%<-- only if you really want to have the first page of a chapter showing the same stuff like the chapter's title just below it...
\begin{document}
\chapter{Title of the chapter}
\blindtext[12]
\end{document}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
KR
Rainer
Emanuelo
Posts: 2
Joined: Sun Apr 22, 2018 9:57 am

fancyhdr: \chaptermark empty

Post by Emanuelo »

Thank you, it works! I did not understood what \chaptermark was and what its relation with \leftmark was. Now I do.

PS: No, I do not want to change the style for the first odd pages ^^.
Post Reply