0

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}
\usepackage[colorlinks=true, allcolors=black]{hyperref}
% 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{}
\chead{\leftmark}
\fancyfoot[C]{\textbf{\thepage}}



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

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

\listoftables\thispagestyle{fancy}
\addcontentsline{toc}{chapter}{List Of Tables\dotfill}

\listoffigures\thispagestyle{fancy}
\addcontentsline{toc}{chapter}{List of Figures\dotfill}
\input{title/Nomenclature}
´´´
1
  • 1
    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)
    – daleif
    Dec 21, 2021 at 10:59

1 Answer 1

1

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
\addcontentsline{toc}{chapter}{Contents\dotfill}
\addtocontents{toc}{\protect\thispagestyle{fancy}}
\tableofcontents
2
  • Thanks a lot!!! Worked like a charm! I did try this actually but I was missing the \newpage command :-/.
    – Kayoshin
    Dec 21, 2021 at 14:35
  • Yes, you should always make sure that you are on the proper page before making changes to the page style (and other page related stuff, like using the current page number in the ToC). Dec 21, 2021 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.