0

My Master's Thesis has a ToC spanning over three pages. The header is defined as.

\setlength{\headheight}{15.2pt}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}
\renewcommand{\subsectionmark}[1]{}
\fancyhead[R]{\itshape{My name here.}}

This works fine for all sections (incl. LoF, LoT). It prints the section name without numbers in the left head, and my name in the right head.

Now there is one problem. On page one and three of the ToC, the left head is "Table of Contents". On page two, however, the head is "CONTENTS". Any suggestions on how to solve this? I'd like to have "Table of Contents" on page two, too.

Here's how the ToC is included:

\newpage
\markright{Table of Contents}
\tableofcontents
\markright{Table of Contents}

So apparently the first \markright is responsible for the header on page one, and the second \markright for the header on page three.

EDIT: A minimal example included below.

\documentclass[a4paper, oneside, 11pt]{article}

\usepackage[a4paper, left=2.5cm, right=2cm, top=3cm, bottom=3cm]{geometry}
\usepackage{fancyhdr}
\usepackage[utf8]{inputenc}
\usepackage[onehalfspacing]{setspace}

\usepackage{titlesec}
\titlespacing*{\section}{0pt}{0pt}{20pt}[0pt]

\usepackage[titles]{tocloft}
\renewcommand{\cftsecfont}{\bfseries}

\renewcommand{\footrulewidth}{0.4pt}


% Header
\setlength{\headheight}{15.2pt}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}
\renewcommand{\subsectionmark}[1]{}
\fancyhead[R]{\itshape{My name here}}


\begin{document}

\pagenumbering{Roman}
\markright{Table of Contents}
\tableofcontents
\addtocontents{toc}{~\hfill\textbf{Page}\par}                   
\markright{Table of Contents}

\newpage
\pagenumbering{arabic}
\section{Introduction}
    \subsection{Subsection 1}
    \subsection{Subsection 2}
    \subsection{Subsection 3}
    \subsection{Subsection 4}
    \subsection{Subsection 5}

\newpage
\section{Study Site}
    \subsection{Subsection 1}
    \subsection{Subsection 2}
    \subsection{Subsection 3}
    \subsection{Subsection 4}

\newpage
\section{Data}
    \subsection{Subsection 1}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
    \subsection{Subsection 2}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
        \subsubsection{Subsubsection 4}
    \subsection{Subsection 3}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}

\newpage
\section{Methods}
    \subsection{Subsection 1}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
    \subsection{Subsection 2}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
        \subsubsection{Subsubsection 4}
    \subsection{Subsection 3}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
    \subsection{Subsection 4}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
    \subsection{Subsection 5}

\newpage
\section{Results}
    \subsection{Subsection 1}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
        \subsubsection{Subsubsection 4}
    \subsection{Subsection 2}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
        \subsubsection{Subsubsection 4}
    \subsection{Subsection 3}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
    \subsection{Subsection 4}
    \subsection{Subsection 5}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}

\newpage
\section{Discussion}
    \subsection{Subsection 1}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
        \subsubsection{Subsubsection 4}
    \subsection{Subsection 2}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
    \subsection{Subsection 3}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
    \subsection{Subsection 4}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2} 
    \subsection{Subsection 5}
    \subsection{Subsection 6}               
    \subsection{Subsection 7}

\newpage
\section{Conclusions}
    \subsection{Subsection 1}
    \subsection{Subsection 2}

\end{document}

Page one

Page two

4
  • (1) welcome, (2) as always on this site, please post a full minimal example instead of sniplet, a full example makes it a lot easier for others to test your code. For example the document class is very important here, but you don't specify anything
    – daleif
    Sep 23, 2018 at 14:29
  • Hi daleif, thanks for your answer. The document class is article. I'll try to create a full example.
    – neacal
    Sep 23, 2018 at 14:32
  • This is not a minimal, others do not have access to the files you are inputting. Please make this self contained. You can use the kantlipsum and its \kant command for sample contents
    – daleif
    Sep 23, 2018 at 14:41
  • Edited again. I haven't included any blind text, since it doesn't seem to be important. I have, however, recreated the structure of the thesis with sections and subsections.
    – neacal
    Sep 23, 2018 at 15:02

1 Answer 1

1

Try this

\makeatletter\let\@mkboth\@gobbletwo\makeatother
\tableofcontents
\makeatletter\let\@mkboth\markboth\makeatother

enter image description here

3
  • thanks for MWE! without it I would not have studied your question.
    – user4686
    Sep 23, 2018 at 16:53
  • Works like a charm, thank you very much for your help! :))
    – neacal
    Sep 24, 2018 at 8:32
  • please help, after this command \markboth does not stop at the content and goes to the next page where it should not be. Oct 2, 2023 at 8:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .