The following code was provided by Martin Scharrer in reply to a post in May 10.
\documentclass{book}
\usepackage[british]{babel}
\usepackage[titles]{tocloft}
\usepackage{tocloft}
\newlength\mylenprt
\newlength\mylenchp
\newlength\mylenapp
\renewcommand\cftpartpresnum{\partname~}
\renewcommand\cftchappresnum{\chaptername~}
\renewcommand\cftchapaftersnum{.}
\settowidth\mylenprt{\cftpartfont\cftpartpresnum\cftpartaftersnum}
\settowidth\mylenchp{\cftchapfont\cftchappresnum\cftchapaftersnum}
\settowidth\mylenapp{\cftchapfont\appendixname~\cftchapaftersnum}
\addtolength\mylenprt{\cftpartnumwidth}
\addtolength\mylenchp{\cftchapnumwidth}
\addtolength\mylenapp{\cftchapnumwidth}
\setlength\cftpartnumwidth{\mylenprt}
\setlength\cftchapnumwidth{\mylenchp}
\usepackage{hyperref}
\hypersetup{colorlinks=true}
\begin{document}
\tableofcontents
\mainmatter
\part{First Part}
\chapter{First Chapter}
\appendix
\addtocontents{toc}{% NB!!! must be inside the first \include
\protect\renewcommand\protect\cftchappresnum{\appendixname~}%
\protect\setlength{\cftchapnumwidth}{\mylenapp}}%
\chapter{First Appendix}
\end{document}
To experiment with hyperlinks, I have added the following to the above.
\usepackage{hyperref}
\hypersetup{colorlinks=true}
After running LaTeX, a table of contents is created with Part I. First Part
as the title of the part above. However, the word Part
, unlike the rest, does not have hyperlink. I wonder how the hyperlink can be extended to include the word Part
.
Best Answer
In this case, instead of using
tocloft
to change the part entries (these entries andtocloft
don't cooperate well), I'd rather redefine the\@part
command (as implemented inbook.cls
):