TransWikia.com

Table of contents with fancyhdr

TeX - LaTeX Asked by user2300369 on August 6, 2021

I attach my MWE.

documentclass[12pt, twoside]{book}
%documentclass[journal=jctcce,manuscript=article]{achemso}
usepackage[a4paper, vmargin=2.5cm, hmargin=2.0cm]{geometry}
usepackage{times} %czcionka Times New Roman
usepackage[latin2]{inputenc} % For english
usepackage{fancyhdr}
usepackage[Bjornstrup]{fncychap}
usepackage{longtable}
usepackage[nottoc,numbib]{tocbibind}
usepackage[bottom]{footmisc}
definecolor{mygray}{gray}{.60}

pagestyle{fancy}

newcounter{chaptercounter}
newcounter{sectioncounter}[chapter]

renewcommand{chaptermark}[1]{markboth{#1}{}}

fancyhf{}

fancyhead[CO]{rightmark} %central odd-number page (section name)
fancyhead[RO]{%
  textcolor{black}{%
%    rightmark
    rlap{%
      hspace{1pt}%
%      hspace{-fboxsep}%
      colorbox{mygray}{%
        makebox[textwidth][l]{thepage}%
      }%
    }%
  }%
}

%fancyhead[RO]{thepage}
fancyhead[CE]{thechapter. MakeUppercase{leftmark}} %central even-number page (chapter name)
fancyhead[LE]{%
  textcolor{black}{%
%    rightmark
    llap{%
      hspace{marginparsep}%
      hspace{-fboxsep}%
      colorbox{mygray}{%
        makebox[textwidth][r]{thepage}%
      }%
    }%
  }%
}

%Usuniecie numerow stron w stopce
fancyfoot[CE,CO]{ }





begin{document}

fontencoding{T1}selectfont %DLa pogrubienia Times New Roman


thispagestyle{empty}

begin{center}
hugebf
DOCTORAL THESIS
end{center}


newpage
frontmatter


chapter{Acknowledgements}
thispagestyle{empty}


thispagestyle{empty}
fancyhead[CO]{MakeUppercase{Contents}} %central odd-number page (section name)
fancyhead[RO]{%
  textcolor{black}{%
%    rightmark
    rlap{%
      hspace{1pt}%
%      hspace{-fboxsep}%
      colorbox{mygray}{%
        makebox[textwidth][l]{thepage}%
      }%
    }%
  }%
}
%fancyhead[RO]{thepage}
fancyhead[CE]{MakeUppercase{Contents}} %central even-number page (chapter name)
fancyhead[LE]{%
  textcolor{black}{%
%    rightmark
    llap{%
      hspace{marginparsep}%
      hspace{-fboxsep}%
      colorbox{mygray}{%
        makebox[textwidth][r]{thepage}%
      }%
    }%
  }%
}


tableofcontents{}
pagestyle{fancy}
fancyhead[CO]{MakeUppercase{leftmark}} %central odd-number page (section name)
fancyhead[RO]{%
  textcolor{black}{%
%    rightmark
    rlap{%
      hspace{1pt}%
%      hspace{-fboxsep}%
      colorbox{mygray}{%
        makebox[textwidth][l]{thepage}%
      }%
    }%
  }%
}

%fancyhead[RO]{thepage}
fancyhead[CE]{MakeUppercase{leftmark}} %central even-number page (chapter name)
fancyhead[LE]{%
  textcolor{black}{%
%    rightmark
    llap{%
      hspace{marginparsep}%
      hspace{-fboxsep}%
      colorbox{mygray}{%
        makebox[textwidth][r]{thepage}%
      }%
    }%
  }%
}

chapter{Foreword}
thispagestyle{empty}


chapter{Glossary of abbreviations and symbols}
thispagestyle{empty}

chapter{ch1}
chapter{ch2}
chapter{ch3}
chapter{ch4}
chapter{ch5}
chapter{ch6}
chapter{ch7}
chapter{ch8}
chapter{ch9}
chapter{ch10}
chapter{ch11}
chapter{ch12}
chapter{ch13}
chapter{ch14}
chapter{ch15}
chapter{ch16}
chapter{ch17}
chapter{ch18}
chapter{ch19}
chapter{ch20}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}
chapter{ch21}

end{document}

I want the central part of the header in table of contents to say "CONTENTS" on both odd and even pages. It does not work on the odd page in this case.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP