1

How can I change the header of ToC by using the solution given by @Bordaigorl here? I want small capitals, like in abstract, chapters and appendix in my example. The same problem is for LoF and LoT. Sorry for the messy code!

\documentclass[twoside]{book}
\usepackage{fancyhdr}
\usepackage[titles]{tocloft}
\usepackage{lipsum} % just for the example
\makeatletter
\fancyhead{}
\fancyfoot{}
\fancyhead[RO]{\textsc{\rightmark}}
\fancyhead[LE]{\textsc{\leftmark}}
\fancyfoot[LE]{\thepage}
\fancyfoot[RO]{\thepage}

\fancypagestyle{plain}{%
\fancyhf{}
\fancyfoot[LE]{\thepage}
\fancyfoot[RO]{\thepage}
}
\pagestyle{fancy}


\g@addto@macro{\frontmatter}{%
    \renewcommand*{\chaptermark}[1]{\markboth{#1}{}}
    \renewcommand*{\sectionmark}[1]{\markright{#1}{}}
}
\g@addto@macro{\mainmatter}{%
    \renewcommand*{\chaptermark}[1]{\markboth{Chapter\space\thechapter:\space#1}{}}
    \renewcommand*{\sectionmark}[1]{\markright{\thesection:\space#1}{}}
}
\g@addto@macro{\appendix}{%
    \renewcommand*{\chaptermark}[1]{\markboth{Appendix\space\thechapter:\space#1}{}}
    \renewcommand*{\sectionmark}[1]{\markright{\thesection:\space#1}{}}
    \addtocontents{loa}{\protect\renewcommand{\protect\cftchappresnum}{\appendixname\space}}
}
\g@addto@macro{\backmatter}{%
    \renewcommand*{\chaptermark}[1]{\markboth{#1}{}}
    \renewcommand*{\sectionmark}[1]{\markright{#1}{}}
}
\makeatother

\begin{document}
\frontmatter
\tableofcontents
\cleardoublepage

\listoffigures
\cleardoublepage

\listoftables
\cleardoublepage

\chapter{Abstract}
\section{Abs1}
\lipsum
\section{Abs2}
\lipsum
\cleardoublepage

\mainmatter
\chapter{A}
\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{Section A}
\lipsum
\cleardoublepage

\chapter{B}
\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{Section B}
\lipsum
\cleardoublepage

\appendix
\chapter{Appendies}
\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{Section App}
\lipsum
\cleardoublepage

\backmatter
\chapter{Bibliography}
\section{Section Bib}
\lipsum
\end{document}

1 Answer 1

1

The definitions of \tableofcontents,\listoffigures and \listoftables have \chapter*{...\@mkboth{\MakeUppercase}{....} etc, i.e. the relevant contentsname is set with uppercase letters, which looks awkward with \scshape etc.

A possible solution is to replace those definitions using \xpatchcmd and use \@mkboth{\scshape \contentsname}{...} etc.

Update -- working for tocloft usage too now:

\documentclass[twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{tocloft}
\usepackage{fancyhdr}
\usepackage{xpatch}
\usepackage{lipsum} % just for the example
\usepackage{fancyhdr}
\makeatletter
\fancyhead{}
\fancyfoot{}
\fancyhead[RO]{\textsc{\rightmark}}
\fancyhead[LE]{\textsc{\leftmark}}
\fancyfoot[LE]{\thepage}
\fancyfoot[RO]{\thepage}

\fancypagestyle{plain}{%
\fancyhf{}
\fancyfoot[LE]{\thepage}
\fancyfoot[RO]{\thepage}
}
\pagestyle{fancy}

\@ifpackageloaded{tocloft}{%
  \renewcommand{\cftmarktoc}{\@mkboth{\scshape \contentsname}{\scshape \contentsname}}
  \renewcommand{\cftmarklof}{\@mkboth{\scshape \listfigurename}{\scshape \listfigurename}}
  \renewcommand{\cftmarklot}{\@mkboth{\scshape \listtablename}{\scshape \listtablename}}
}{%
\xpatchcmd{\tableofcontents}{%
  \chapter*{\contentsname
    \@mkboth{%
      \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
}{%
  \chapter*{\contentsname\@mkboth{\scshape \contentsname}{\scshape \contentsname}}%
}{}{}%

\xpatchcmd{\listoffigures}{%
  \chapter*{\listfigurename}%
  \@mkboth{\MakeUppercase\listfigurename}%
  {\MakeUppercase\listfigurename}%
}{%
  \chapter*{\listfigurename\@mkboth{\scshape \listfigurename}{\scshape \listfigurename}}%
}{}{}

\xpatchcmd{\listoftables}{%
  \chapter*{\listtablename}%
  \@mkboth{\MakeUppercase\listtablename}%
  {\MakeUppercase\listtablename}%
}{%
  \chapter*{\listtablename\@mkboth{\scshape \listtablename}{\scshape \listtablename}}%
}{}{}
}

\g@addto@macro{\frontmatter}{%
    \renewcommand*{\chaptermark}[1]{\markboth{#1}{}}
        \renewcommand*{\sectionmark}[1]{\markright{#1}{}}
}
\g@addto@macro{\mainmatter}{%
    \renewcommand*{\chaptermark}[1]{\markboth{Chapter \thechapter{}:\space#1}{}}
        \renewcommand*{\sectionmark}[1]{\markright{\thesection{}:\space#1}{}}
}
\g@addto@macro{\appendix}{%
    \renewcommand*{\chaptermark}[1]{\markboth{\textsc{Appendix \thechapter{}:}\space#1}{}}
        \renewcommand*{\sectionmark}[1]{\markright{\thesection{}:\space#1}{}}
        \addtocontents{loa}{\protect\renewcommand{\protect\cftchappresnum}{\appendixname\space}}
}
\g@addto@macro{\backmatter}{%
    \renewcommand*{\chaptermark}[1]{\markboth{#1}{}}
        \renewcommand*{\sectionmark}[1]{\markright{#1}{}}
}
\makeatother

\begin{document}
\frontmatter
\tableofcontents
\cleardoublepage
\listoffigures
\cleardoublepage
\listoftables

\chapter{Abstract}
\section{Abs1}
\lipsum
\section{Abs2}
\lipsum
\cleardoublepage

\mainmatter
\chapter{A}
\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{A}\section{Section A}
\lipsum
\cleardoublepage

\chapter{B}
\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{B}\section{Section B}
\lipsum
\cleardoublepage

\appendix
\chapter{Appendies}
\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{app}\section{Section App}
\lipsum
\cleardoublepage

\backmatter
\chapter{Bibliography}
\section{Section Bib}
\lipsum
\end{document}

enter image description here

11
  • If I copy-paste your solution to MikTeX or shareLaTeX (online), then I don't get the same result as you? /Tobias Link to shareLaTeX: sharelatex.com/project/56e67961919001405f72558a
    – TobiasDK
    Mar 14, 2016 at 10:41
  • @TobiasDK: Blame ShareLaTeX then. Its TeX distribution is often very outdated
    – user31729
    Mar 14, 2016 at 10:43
  • Same problem with my MikTeX with is updated today.
    – TobiasDK
    Mar 14, 2016 at 10:50
  • Logfile with \listfiles: db.tt/YQlStHOT
    – TobiasDK
    Mar 14, 2016 at 10:56
  • @TobiasDK: I posted an intermediate version accidentally. The current version is the one that produces the output!
    – user31729
    Mar 14, 2016 at 11:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .