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}
You can write what is naturally done by \addcontentsline
manually using \addtocontents{toc}
:
\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 \chapter
s 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With