9

In the tufte-book document class, I am having a hard time figuring out how to insert the chapter name in the header of right odd-numbered pages with the fancyhdr package. Something like:

Chapter 2. Chapter title.

From the .def file:

% The 'fancy' page style is the default style for all pages.
\fancyhf{} % clear header and footer fields
\ifthenelse{\boolean{@tufte@twoside}}
  {\fancyhead[LE]{\thepage\quad\smallcaps{\newlinetospace{\plaintitle}}}
    \fancyhead[RO]{\smallcaps{\newlinetospace{\chaptername{}~\thechapter}}\quad\thepage}}
  {\fancyhead[RE,RO]{\smallcaps{\newlinetospace{\chaptername{}~\thechapter}}\quad\thepage}}

I understand that \leftmark and \rightmark usually do the trick, but what's the exact command to get only the title of the chapter?

2 Answers 2

20

There are three bits of information for each chapter:

  1. \thechapter, which is the number. (For instance, 2 of "Chapter 2.")
  2. \chaptername, which is the current language equivalent of the word "chapter."
  3. And \chaptermark, the actual title of the chapter.

It looks like you're looking for \chaptermark. See also Section 9 of the fancyhdr documentation, especially Figure 3, which shows one way to do this:

\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}

Edit: After looking at this again, it looks like tufte-book doesn't even have chapter numbers. (This is where a MWE could have helped.) How's this?

\documentclass{tufte-book}
\usepackage{fancyhdr}
\usepackage{lipsum}

\setcounter{secnumdepth}{0}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[RO]{\textsc{\nouppercase{\newlinetospace{{\leftmark}}\quad\thepage}}}

\begin{document}

\chapter{Sample Title}
\lipsum[1-9]

\chapter{Another Sample Title}
\lipsum[1-9]

\chapter{And One More}
\lipsum[1-9]

\end{document}
3
  • Thanks a lot, Sam! So if I add your definition of \chaptermark, can I simply do this: \fancyhead[RO]{\smallcaps{\newlinetospace{\chaptername{}~\thechapter. \chaptermark}}\quad\thepage}}? It doesn't work. I don't understand how to integrate your solution with the bits of code I provided, which I took from the tufte-book definition file. May 18, 2016 at 15:20
  • Something is amiss here; maybe it's \smallcaps? I've edited the answer with an ugly fix.
    – Richard
    May 19, 2016 at 5:41
  • \smallcaps seems to work with your \renewcommand{\chaptermark}[1]{% \markboth{#1}{}}, which retrieves only the chapter name, without the text saying chapter and then the chapter number. So I integrated your solution into mine and it works now! May 19, 2016 at 13:09
2

In the end I integrated the answer given by Sam into the bits of code I was suggesting in my question. The following works:

\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}  
\fancyhf{} % clear header and footer fields
\ifthenelse{\boolean{@tufte@twoside}}
  {\fancyhead[LE]{\thepage\quad\smallcaps{\newlinetospace{\plaintitle}}}%
    \fancyhead[RO]{\smallcaps{\newlinetospace{\chaptername{}~\thechapter. \leftmark}}\quad\thepage}}
  {\fancyhead[RE,RO]{\smallcaps{\newlinetospace{\chaptername{}~\thechapter. \leftmark}}\quad\thepage}}

This gives the book title on left pages and the chapter title on right pages.

For some reason, \smallcaps works with this redefinition of chaptermark, which only gives the chapter title:

\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}

... and not with the following one, which yields the word chapter, followed by the chapter number and its full title:

\renewcommand{\chaptermark}[1]{%
\markboth{\MakeUppercase{%
\chaptername\ \thechapter.%
\ #1}}{}}
3
  • 1
    You might consider letting the tufte-latex folks know about the issue. They might be able to help!
    – Richard
    May 19, 2016 at 19:31
  • Well, they denied me access to their google group... May 20, 2016 at 8:59
  • Hi, my problem is just similar to this. I am using documentclass 'report' . And I wanted to show custom header and footer, So, I used following: \fancyhead{} \fancyfoot[C]{Address} \fancyfoot[R]{\thepage} \fancyhead[L]{ \text{ \large{\chaptername \thechapter}}} \fancyhead[R]{\text{ \large{\chaptermark}}} . All worked fine except last command, actually i wanted to show only chaptername that i defined using \chapter{ } command, but it did not worked. To solve I do hard coding like: \fancyhead[R]{\text{ \large{Number System}}}. How can I get chaptername automatically on right header. Help me! Jul 16, 2017 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.