LaTeX forum ⇒ Page Layoutfancyhdr: \chaptermark empty Topic is solved

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

fancyhdr: \chaptermark empty  Topic is solved

Postby Emanuelo » Sun Apr 22, 2018 10:27 am

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 :
  1. \documentclass[12pt,a4paper]{book}
  2. \usepackage{polyglossia}
  3. \setdefaultlanguage{english}
  4. \usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
  5. \usepackage{fancyhdr}
  6. \pagestyle{fancy}
  7. \fancyhead{}
  8. \fancyhead[RO,LE]{\thepage}
  9. \fancyhead[CE]{Title of the book}
  10. \fancyhead[CO]{\chaptermark}
  11. \fancyfoot{}
  12. \renewcommand{\headrulewidth}{0.4pt}
  13. \renewcommand{\footrulewidth}{0pt}
  14. \begin{document}
  15. \chapter{Title of the chapter}
  16. \end{document}


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!

Tags:

rais
Posts: 173
Joined: Sun Nov 16, 2014 8:51 pm

Postby rais » Sun Apr 22, 2018 11:20 am

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:
  1. \documentclass[12pt,a4paper]{book}
  2. \usepackage{polyglossia}
  3. \usepackage{blindtext}
  4. \setdefaultlanguage{english}
  5. \usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
  6. \usepackage{fancyhdr}
  7. \pagestyle{fancy}
  8. \fancyhead{}
  9. \fancyhead[RO,LE]{\thepage}
  10. \fancyhead[CE]{Title of the book}
  11. %\fancyhead[CO]{\chaptermark}<-- \chaptermark has no place here. It is used to *set* the mark(s) for a chapter, not to get it.
  12. \fancyhead[CO]{\leftmark}
  13. \fancyfoot{}
  14. \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
  15. \renewcommand{\headrulewidth}{0.4pt}
  16. \renewcommand{\footrulewidth}{0pt}
  17. \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...
  18. \begin{document}
  19. \chapter{Title of the chapter}
  20. \blindtext[12]
  21. \end{document}

KR
Rainer

Emanuelo
Posts: 2
Joined: Sun Apr 22, 2018 9:57 am

Postby Emanuelo » Sun Apr 22, 2018 11:37 am

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 ^^.


Return to “Page Layout”

Who is online

Users browsing this forum: No registered users and 2 guests