# How do I prevent “Contents” from appearing twice in the header when I use \leftmark and \rightmark with fancyhdr?

I would like to use \leftmark and \rightmark, but have "Contents" appear only once (on the left) in the header. Instead, it appears as both the \leftmark and the \rightmark.

The following MWE illustrates the problem:

\documentclass[12pt]{article}
\usepackage{fancyhdr}
\pagestyle{fancy}

\begin{document}
\tableofcontents
\end{document}
-
If you have at least one \section command in the same page of your ToC, the problem disappears. –  Gonzalo Medina Mar 18 '12 at 0:04
@Gonzalo Medina Yes. Unfortunately the ToC takes up a full page. –  Will Mar 18 '12 at 0:15

Change the definition of \tableofcontents.

\documentclass[12pt]{article}
\usepackage{fancyhdr}
\pagestyle{fancy}

\makeatletter
\renewcommand\tableofcontents{%
\section*{\contentsname
\@mkboth{%
%           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}% DELETED
\@starttoc{toc}%
}
\makeatother

\begin{document}
\tableofcontents
\end{document}
-
Perfect, thank you. How would I make it appear only on the right? –  Will Mar 18 '12 at 0:14
@Will By removing the first \MakeUppercase\contentsname from the definition instead of the second one. –  lockstep Mar 18 '12 at 0:21
@Will Note, however, that \tableofcontents is considered a section in the article class, and therefore should change \leftmark. Wether it should change \rightmark too is more debatable. –  lockstep Mar 18 '12 at 0:25

The user guide to the fancyhdr package notes on p. 10 that

It should be noted that the LATEX marking mechanism works fine with chapters (which always start on a new page) and sections which are reasonably long. It does not work quite as well with short sections and subsections. This is a problem with LATEX, not with fancyhdr.

AFAICT, an easy workaround, which doesn't require the redefinition of LaTeX's \tableofcontents command, consists of specifying \rhead{} before the \tableofcontents command, followed by \rhead{\rightmark} before the first section:

\documentclass[12pt]{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\begin{document}
\tableofcontents

\clearpage   % OP has indicated that ToC spans a full page

\section{Hello}
\end{document}
-
I prefer customization in the preamble, but +1 for the fancyhdr quote. –  lockstep Mar 18 '12 at 0:27

\rightmark uses the first right mark of the page. So you can also set before \tableofcontents an empty \markright to get rid of the right mark on the first page and use an addtocontents to insert a \markright in the toc to get rid of the right mark on the following pages:

\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}

\begin{document}
\markright{}
\tableofcontents