1

I'm using fancyhdr for editing the header of my document. I have the following code:

\documentclass[a4paper,12pt,oneside,titlepage]{book}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\rhead{\small\bfseries\leftmark\quad\thepage}
\renewcommand{\headrulewidth}{0.4pt}

\fancypagestyle{plain}{
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}}

\renewcommand{\chaptermark}[1]{
\markboth{\thechapter.\ #1}{}}

\begin{document}

\tableofcontents
\markboth{\contentsname}{\contentsname}

\listoftables
\markboth{\listtablename}{\listtablename}

\listoffigures
\markboth{\listfigurename}{\listfigurename}

\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}
\chapter{Test}

\end{document}

which correctly display chapter number, chapter name (in lower case), page number and a line below, in the top right corner of each page, except the first of each chapter. I only have an issue with the table of contents: the second page show "INDEX ii", while the third (correctly) show "Index iii". Why I have this inconsistency?

  • I'm not sure I can reproduce your problem here. I just added some dummy chapters and a \tableofcontents, and I get CONTENTS <page#> in the header on each page of the table of contents. How do you issue your table of contents? Do you override the default chapter marks? – phfaist May 23 '14 at 13:36
  • Yes, I redefined the default chapter mark in the two last line of the above code. – Andrea May 23 '14 at 13:48
  • ... but I took your complete code above and I can't reproduce your problem. What else did you change? – phfaist May 23 '14 at 14:14
  • 2
    Please post a complete small document demonstrating your issue so that people can reproduce. This is much more useful than a mere code fragment (as this case illustrates well). Also, do you really want both oneside and openright? The latter only seems to make sense for twoside. – cfr May 23 '14 at 14:20
  • I, too, cannot reproduce your specific issue. Consider that \chaptermark doesn't get called for the contents section. You can manually adjust the leftmark for the contents with something like \addtocontents{toc}{\protect\markboth{\contentsname}{}}. – cslstr May 23 '14 at 14:21
1

I still can't reproduce your problem as you've stated it. I'm now extrapolating what you might be trying to do: I'm assuming you're using a manual \markboth command for the table of contents, such as something similar to:

\tableofcontents
\markboth{Index}{}

and then the \markboth command only takes effect on the last page of the table of contents, as one can expect.

So, not sure now if I'm answering your question, but speculating: if you don't want the header to be upper cased, you can use the following code:

{
  \renewcommand{\MakeUppercase}[1]{#1}
  \tableofcontents
}

LaTeX uses \MakeUppercase when defining the marks for e.g. the table of contents (you can check in book.cls source), so the \renewcommand makes it now ineffective. The braces ensure that \MakeUppercase will continue to behave normally in the rest of the document.

Also, with the book document class, I get Contents in the header, not Index as you describe. If you want to change that, you can use

\renewcommand\contentsname{Index}

But I'd expect Index is usually rather used for a lookup index at the end of the book, with keywords and pages where those terms appear.

  • I posted a complete document with my issue. As you speculated, I'm probably misusing the markboth command, which has effect on the last page only (and not on all the page, as I though). – Andrea May 24 '14 at 13:24
  • @Andrea The \markboth command seems to be issued after the table of contents is generated, so it only affects the last page (the one that's not completed yet). LaTeX itself calls \markboth inside the \tableofcontents command with arguments \MakeUppercase{\contentsname} (see book.cls: \@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname} with \@mkboth alias of \markboth), so that's why I suggest you redefine \MakeUppercase to be ineffective for when LaTeX will call it from \tableofcontents. (But there may be other ways to achieve this.) – phfaist May 25 '14 at 17: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.