Formatting unnumbered chapters in TOC

3.5k views Asked by At

I have a document with both numbered and unnumbered chapters. To distinguish them from each other in the TOC I would like the unnumbered chapters to be in italic. My MWE works on the chapter title - how can I format the corresponding page number in italic?

Also, is it possible to centre the Part 1 entry?

\documentclass[a4paper, 12pt]{report}

\usepackage[titles]{tocloft}

\begin{document}
\tableofcontents

\part{Part 1}

\chapter{Numbered chapter}

\chapter*{Unnumbered chapter}
\addcontentsline{toc}{chapter}{\textit{Unnumbered chapter}}

\end{document}
1

There are 1 answers

0
Werner On BEST ANSWER

You can write what is naturally done by \addcontentsline manually using \addtocontents{toc}:

enter image description here

\documentclass{report}

\usepackage[titles]{tocloft}

\begin{document}

\tableofcontents

\chapter{Numbered chapter}

\chapter*{Unnumbered chapter}
\addtocontents{toc}
  {\protect\contentsline{chapter}{\textit{Unnumbered chapter}}{\textit{\thepage}}}

\end{document}

The above should work for \chapters since they are typically set on a new page and therefore \thepage would result in the correct value. However, it does not work with hyperref.

Alternatively, define a new type of ToC-entry called chapterstar:

\documentclass{report}

\usepackage[titles]{tocloft}
\usepackage{etoolbox}

\makeatletter
\let\l@chapterstar\l@chapter
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\l@chapterstar}{\cftchapfont}{\cftchapstarfont}{}{}% Insert starred chapter font
\patchcmd{\l@chapterstar}{#2}{\cftchapstarpagefont #2}{}{}% Insert starred chapter page number font
\makeatother

\newcommand{\cftchapstarfont}{\cftchapfont\itshape}
\newcommand{\cftchapstarpagefont}{\cftchappagefont\itshape}

\begin{document}

\tableofcontents

\chapter{Numbered chapter}

\chapter*{Unnumbered chapter}
\addcontentsline{toc}{chapterstar}{Unnumbered chapter}

\end{document}

The above solution works with hyperref and is more generic.