1

Following this solution, I have been able to successfully add an unnumbered chapter to a table of contents (ToC) and italicise the font. However, my unnumbered chapter consists of unnumbered sections, which I would also like add to the ToC in italics. The code I have at the moment (below) does this successfully. My problem is the generated bookmark (as viewed in my PDF reader) of the unnumbered section is at the chapter level, rather than the section level. How do I ensure the bookmark is generated at the correct level?

\documentclass{report}

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

\makeatletter
\let\l@chapterstar\l@chapter
\patchcmd{\l@chapterstar}{\cftchapfont}{\cftchapstarfont}{}{}
\patchcmd{\l@chapterstar}{#2}{\cftchapstarpagefont #2}{}{}
\makeatother

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

\makeatletter
\let\l@sectionstar\l@section
\patchcmd{\l@sectionstar}{\cftsecfont}{\cftsecstarfont}{}{}
\patchcmd{\l@sectionstar}{#2}{\cftsecstarpagefont #2}{}{}
\makeatother

\newcommand{\cftsecstarfont}{\cftsecfont\itshape}
\newcommand{\cftsecstarpagefont}{\cftsecpagefont\itshape}   

\begin{document}

\tableofcontents

\chapter{Numbered chapter}

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

\section*{Unnumbered section}
\addcontentsline{toc}{sectionstar}{Unnumbered section}

\end{document}
1

Add

\def\toclevel@chapterstar{0}

and

\def\toclevel@sectionstar{1}

to the preamble.

Example:

\documentclass{report}
\usepackage[titles]{tocloft}
\usepackage{etoolbox}
\usepackage{hyperref}

\makeatletter
\let\l@chapterstar\l@chapter
\patchcmd{\l@chapterstar}{\cftchapfont}{\cftchapstarfont}{}{}
\patchcmd{\l@chapterstar}{#2}{\cftchapstarpagefont #2}{}{}
\def\toclevel@chapterstar{0}% <- added
\makeatother

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

\makeatletter
\let\l@sectionstar\l@section
\patchcmd{\l@sectionstar}{\cftsecfont}{\cftsecstarfont}{}{}
\patchcmd{\l@sectionstar}{#2}{\cftsecstarpagefont #2}{}{}
\def\toclevel@sectionstar{1}% <- added
\makeatother

\newcommand{\cftsecstarfont}{\cftsecfont\itshape}
\newcommand{\cftsecstarpagefont}{\cftsecpagefont\itshape}   

\begin{document}
\tableofcontents
\chapter{Numbered chapter}

\chapter*{Unnumbered chapter}
\addcontentsline{toc}{chapterstar}{Unnumbered chapter}
\section*{Unnumbered section}
\addcontentsline{toc}{sectionstar}{Unnumbered section}
\end{document}

enter image description here

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.