[Tex/LaTex] “CONTENTS” in header issue

formattingheader-footerluatexsectioningtable of contents

I am currently using a header on my document that should do one of a few things.

If the current page is before any chapters or sections are defined, the header should only contain a number.

If there are any sections or chapters defined before the current page, the name of the last defined section / chapter should be in the header.

There are two excpetions to this rule. If there is a new chapter, there should be no header on the page or table of contents.

If there is a title page, there should be no footer / header.

This works great. However, when a table of contents is added, all the headers become prefixed with CONTENTS. How can I prevent the headers being prefixed with CONTENTS without affecting any of the header functionality that was described above.

There is also a case when there is no section or title in the header, but there is a table of contents, the header is consists of CONTENTSCONTENTS.

If it makes a difference, I am building using LuaTex on the latest version of TexLive (downloaded today)

\documentclass[a4paper,oneside]{book}
\usepackage{lipsum}
\usepackage{fancyhdr}

%Header / Footer info
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markright{#1}}
\renewcommand{\sectionmark}[1]{\markright{#1}}

%Define the header / footer
\fancyhf{}
\fancyhead[L]{\topmark}
\fancyhead[R]{\thepage}
\renewcommand{\headrulewidth}{0pt}

\begin{document}
\begin{titlepage}
hello
\end{titlepage}
\tableofcontents
\clearpage
\lipsum[1-10]
\clearpage
\section{Paragraphs 1 - 10}
\lipsum[1-10]
\clearpage
\chapter{Lorem Ipsum :)}
\lipsum[1-5]
\section{Paragraphs 6 - 10}
\lipsum[6-10]
\section{Paragraphs 11 - 15}
\lipsum[11-15]
\end{document}

Best Answer

What you are asking is how to get rid of the header "CONTENTS", which is being carried over from the TOC into the beginning of the main text. That header is present because it is being held as a mark.

You therefore want to obliterate all existing marks when you begin the main text. The easiest way to do this is to add this command immediately after the \clearpage that closes out the contents:

\markboth{}{}
Related Question