2

I am looking for a way to make both frontmatter and backmatter chapters non-bold italic in the Table of Contents.

For the frontmatter chapters, I found a short and well-working solution here by Christian Hupfer: Different style for frontmatter chapters in TOC

It uses the tocloft package and its commands \cftchapterfont and \cftchapterpagefont.

My question is how to extend this to work for the backmatter chapters too?

1

Just redefine the \appendix macro in the same way if you're using KOMA like the OP of the linked question:

\documentclass{scrbook}
\makeatletter
\newcommand\matter@switch{}
\addtokomafont{chapterentry}{\matter@switch}
\g@addto@macro\frontmatter{%
  \addtocontents{toc}{%
    \protect\renewcommand\protect\matter@switch{\normalfont\itshape}%
  }%
}
\g@addto@macro\mainmatter{%
  \addtocontents{toc}{%
    \protect\renewcommand\protect\matter@switch{}%
  }%
}
\g@addto@macro\appendix{%
  \addtocontents{toc}{%
    \protect\renewcommand\protect\matter@switch{\normalfont\itshape}%
  }%
}
\makeatother
\begin{document}
\frontmatter
\tableofcontents
\chapter{Preface}
\chapter{Acknowledgements}
\mainmatter
\chapter{First Chapter}
\chapter{Second Chapter}
\appendix
\chapter{Appendix}
\end{document}

Or introduce similar code if you're not using KOMA but tocloft:

\documentclass{book}
\usepackage{tocloft}%
\begin{document}
\let\cftchapfontorig\cftchapfont
\let\cftchappagefontorig\cftchappagefont
\renewcommand{\cftchapfont}{\itshape}
\renewcommand{\cftchappagefont}{\itshape}%
\frontmatter
\chapter{Preface}
\chapter{Acknowledgements}
\tableofcontents
\addtocontents{toc}{\protect\renewcommand{\protect\cftchapfont}{\cftchapfontorig}}
\addtocontents{toc}{\protect\renewcommand{\protect\cftchappagefont}{\cftchappagefontorig}}
\mainmatter
\chapter{First Chapter}
\chapter{Second Chapter}
\addtocontents{toc}{\protect\renewcommand{\protect\cftchapfont}{\itshape}}
\addtocontents{toc}{\protect\renewcommand{\protect\cftchappagefont}{\itshape}}
\appendix
\chapter{Appendix}
\end{document}
1

Here is another suggestion using package tocbasic.

With a KOMA-Script class:

\documentclass{scrbook}% loads tocbasic automatically

\DeclareTOCStyleEntry[
  entryformat=\chapterentryformat,
  pagenumberformat=\chapterentryformat
]{tocline}{chapter}
\newif\ifmainmatterintoc
\newcommand*\chapterentryformat[1]
  {{\ifmainmatterintoc\usekomafont{chapterentry}\else\normalfont\slshape\fi#1}}

\begin{document}
\frontmatter
\chapter{Preface}
\chapter{Acknowledgements}
\tableofcontents
\mainmatter
\addtocontents{toc}{\protect\mainmatterintoctrue}
\chapter{First Chapter}
\chapter{Second Chapter}
\backmatter
\addtocontents{toc}{\protect\mainmatterintocfalse}
\chapter{First Backmatter Chapter}
\chapter{Second Backmatter Chapter}
\end{document}

enter image description here

With a standard class:

\documentclass{book}
\usepackage{tocbasic}
\DeclareTOCStyleEntry[
  entryformat=\chapterentryformat,
  pagenumberformat=\chapterentryformat
]{tocline}{chapter}
\newif\ifmainmatterintoc
\newcommand*\chapterentryformat[1]
  {{\ifmainmatterintoc\bfseries\sffamily\else\normalfont\slshape\fi#1}}

\begin{document}
\frontmatter
\chapter{Preface}
\chapter{Acknowledgements}
\tableofcontents
\mainmatter
\addtocontents{toc}{\protect\mainmatterintoctrue}
\chapter{First Chapter}
\chapter{Second Chapter}
\backmatter
\addtocontents{toc}{\protect\mainmatterintocfalse}
\chapter{First Backmatter Chapter}
\chapter{Second Backmatter Chapter}
\end{document}

![enter image description here

It is also possible to patch \mainmatter and \appendix in the preamble:

\documentclass{book}
\usepackage{tocbasic}
\DeclareTOCStyleEntry[
  entryformat=\chapterentryformat,
  pagenumberformat=\chapterentryformat
]{tocline}{chapter}
\newif\ifmainmatterintoc
\newcommand*\chapterentryformat[1]
  {{\ifmainmatterintoc\bfseries\sffamily\else\normalfont\slshape\fi#1}}

\usepackage{xpatch}
\xapptocmd\mainmatter{\addtocontents{toc}{\protect\mainmatterintoctrue}}
  {}{\mmPatchFailed}
\xapptocmd\backmatter{\addtocontents{toc}{\protect\mainmatterintocfalse}}
  {}{\appPatchFailed}

\begin{document}
\frontmatter
\chapter{Preface}
\chapter{Acknowledgements}
\tableofcontents
\mainmatter
\chapter{First Chapter}
\chapter{Second Chapter}
\backmatter
\chapter{First Backmatter Chapter}
\chapter{Second Backmatter Chapter}
\end{document}

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.