# Add Header to TOC TableofContent, error with \tableofcontents

I am encountering a weird problem.

I've been trying to get a header into my Contents page. For reason using \thispagestyle{fancy} along with \usepackage{fancyhdr} in the preamble does not "recognize" my first page of the table of contents. Not only is the header missing, but the page number in the table of contents starts with Page number IV although the contents page starts at III. Do you have any idea what I might be doing wrong? Please find my code below:

%% Language and font encodings

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{titlesec}

\titleformat{\chapter}[hang]
{\centering\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{0.5em}{}
\titlespacing*{\chapter}{0pt}{0pt}{20pt}

\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\usepackage{bm}

%% Sets page size and margins
\usepackage[usegeometry]{typearea}

\usepackage[a4paper,top=3cm,bottom=3cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

%% Useful packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
% For Tables:
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{lscape}

\usepackage{scrlayer}

\usepackage{array, makecell}
\usepackage{longtable}
%Chinese Language packets
\usepackage{xeCJK}
\usepackage{zhnumber}

\usepackage{rotating}
\usepackage{afterpage}
\usepackage{arydshln}
\usepackage{geometry}
\usepackage{siunitx}

\title{some title}
\author{name}
% Update supervisor and other title stuff in title/title.tex

\begin{document}

\input{title/title_chinese.tex}
\input{title/title_english.tex}
\input{title/Supervisors.tex}
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[C]{\textbf{\thepage}}

\pagenumbering{Roman}
\input{Abstract/abstract}\thispagestyle{fancy}

\listoftables\thispagestyle{fancy}

\listoffigures\thispagestyle{fancy}
\input{title/Nomenclature}
´´´

• Please extend your example to a full (there is no document class), self contained example (you are using \input on files we do not have access to, so we cannot test your code) Dec 21, 2021 at 10:59

The problem is with this line:

\tableofcontents{\protect\thispagestyle{fancy}}\addcontentsline{toc}{chapter}{Contents\dotfill}


You do the \thispagestyle{fancy} after the tableofcontents, so it affects only the last page of it. And then you add "Contents\dotfill" to the ToC, but then it is already on the last page, so you will get that page number.

Replace that line with the following:

\newpage