-1

enter image description hereMy book class document has chapter titles only on LE and RO pages, and I want the same in the contents pages too. I tried totally removing the headers with \makeatletter \let\@mkboth\relax \makeatother and adding \fancyhead[LE,RO]{\leftmark}, but that resulted in the word Contents appearing in upper case adjacent to the title of the toc. A MWE is given below, and an image of what I get is added:

\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{lipsum}% used to get dummy text
\begin{document}
\pagestyle{fancy}
\makeatletter
\let\@mkboth\relax
\makeatother
\tableofcontents%
\fancyhead[LE,RO]{\leftmark}
\cleardoublepage
\chapter{Chapter 1}
\section{Section 1.1}
\lipsum[1]% used to get dummy text
\cleardoublepage
\chapter{Chapter 2}
\section{Section 2.1}
\lipsum[2]% used to get dummy text
\chapter{Chapter 3}
\section{Section 3.1}
\lipsum[3]% used to get dummy text
\end{document}

Any pointer to a solution is appreciated.

The kind of headers I need for the Contents pages, except for the first page, as in all chapters is as shown in the image below:Sample Contents pages I need, except the first page

  • What exactly is the desired behaviour? There should also be the chapter title (i.e. "Contents") appearing on the page of the table of contents? What about the opening pages of chapters? Or do you want it removed somewhere (this is what your code suggests)? – Tiuri Dec 02 '19 at 11:16
  • The opening page of each chapters is plain with just the page number at the bottom. That is coming like that. The MWE is meant to show only the behaviour of the contents pages, as the other pages have no problem. Sorry, if that was not clear. – Kaduba House Dec 02 '19 at 11:51
  • Still, what is the desired behaviour for the page of the table of contents? You write that you want to have headlines there, but at the same time insert code that looks like you want to remove the headlines. Please clarify. – Tiuri Dec 02 '19 at 13:04
  • I want no header in the contents pages, but I do want the title, "Contents" there, I don't want any header in the first page of a chapter, but do need them in the other pages. The other pages are coming as I want them to, but have a problem only in the contents pages. I hope that makes it clear. The code I have inserted is meant to remove the headers from the contents pages, which it does, but introduces the word "CONTENTS" in capitals, as seen in the screenshot. – Kaduba House Dec 02 '19 at 13:35
  • I really don't understand what you are trying to achieve. Leaving out the \makeatletter ... \makeatother part, I get titles for the contents and the chapters on the respective first pages, and properly labelled headers on all subsequent pages. Maybe you can use a graphics program to sketch how the result should look like? – Tiuri Dec 02 '19 at 14:49
  • I have no problem with other chapters, their titles or the title on the contents page. I just want headers on LO and RE of contents pages. So, I wanted to first remove all headers on the contents pages and add these two using the fancyhead command. That is why I inserted the code to disable markboth. But, then, I got two additional "CONTENTS" in upper case along with the title on the contents page, as shown in the screenshot. – Sasi Dec 03 '19 at 15:09
  • My problem is not about titles, I don't know why that came in. I want headers in the 2nd, 3rd, etc, pages of the Contents only on the left side of even pages and right side of odd pages (RO,LE), as we specify in fancyheader. By default it appears on both sides of every page, which I don't want. So, I was trying to remove the headers totally and then add using fancyheader, which doesn't work. I don't know any other way to do that. – Sasi Dec 06 '19 at 13:53

1 Answers1

1

Edit after comment: I think I finally understand what is the question you actually want to answer.

I use fancyhdr to have chapter and section titles in the header. However, for the pages of the table of contents, the chapter title "CONTENTS" appears on both sides of the header, i.e. also as the section title. How can I remove it from the one side of the header?

This has a simple answer: Use \markright{} to clear the "section title" part of the header. You can do so by wrapping it into \addtocontents{toc} (to have it right after the chapter title calls \markboth on the first page of the contents) and \AtBeginDocument (to have it at the first "entry" in the table of contents).

\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{lipsum}% used to get dummy text
\AtBeginDocument{\addtocontents{toc}{\protect\markboth{\textsl{CONTENTS}}{}}} 
\begin{document}
\pagestyle{fancy}
\tableofcontents%
\cleardoublepage
\chapter{Chapter 1}
\section{Section 1.1}
\lipsum[1]% used to get dummy text
\cleardoublepage
\chapter{Chapter 2}
\section{Section 2.1}
\lipsum[2]% used to get dummy text
\chapter{Chapter 3}
\section{Section 3.1}
\lipsum[3]% used to get dummy text
\end{document}

Header from page 2: enter image description here


Old answer:

Without any manual intervention, the default header at the subsequent pages of the table of contents has "CONTENTS" in captial letters both left and right. The first page of the table of contents doesn't have any header, as all other opening pages of chapters.

\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{lipsum}% used to get dummy text
\begin{document}
\pagestyle{fancy}
\tableofcontents%
\cleardoublepage
\chapter{Chapter 1}
\section{Section 1.1}
\lipsum[1]% used to get dummy text
\cleardoublepage
\chapter{Chapter 2}
\section{Section 2.1}
\lipsum[2]% used to get dummy text
\chapter{Chapter 3}
\section{Section 3.1}
\lipsum[3]% used to get dummy text
\end{document}

Header from page 2: enter image description here


To modify what is put into the header for the pages of the table of contents, you have to call \markboth which overwrites what has already been put there by the caption of the table of contents. There is no need to hack any other commands to not call \markboth or related commands, as the purpose of these macros is really to overwrite what is already there. So you really only need to call \markboth after the chapter heading of the table of contents and before the first page break, i.e. ideally directly after the chapter heading.

Inspired by this answer, I would add the \markboth call to the TOC as first entry (so that it's called directly after the chapter heading). To make sure that it's the first entry, you can use \AtBeginDocument in the preamble. Minimal example:

\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{lipsum}% used to get dummy text
\AtBeginDocument{\addtocontents{toc}{\protect\markboth{Contents}{\textnormal{More Contents}}}} 
\begin{document}
\pagestyle{fancy}
\tableofcontents%
\cleardoublepage
\chapter{Chapter 1}
\section{Section 1.1}
\lipsum[1]% used to get dummy text
\cleardoublepage
\chapter{Chapter 2}
\section{Section 2.1}
\lipsum[2]% used to get dummy text
\chapter{Chapter 3}
\section{Section 3.1}
\lipsum[3]% used to get dummy text
\end{document}

Header from page 2: enter image description here

You will of course now want to modify this, to have the exact wording and also text formatting style for the header that you need. Note that the default style (at least in this minimal example) is italicized text, so you may need to overwrite that.

Tiuri
  • 7,749
  • Thank you very much. But this is only modifying the existing headers. What I want is to get headers only on one side of each page of the ToC, namely, left header on even pages and right header on odd pages. I know how to do that only using the fancyhdr package, which is why I tought of totally disabling markboth and adding headers using fancyhdr, which didn't work. But let me see how I can do it using this new bit of information. – Kaduba House Dec 05 '19 at 04:12
  • @KadubaHouse see the updated answer. – Tiuri Dec 05 '19 at 10:12