[Tex/LaTex] Table of contents — changing headings

numberingtable of contents

I use \tableofcontents to generate a ToC of a book. It uses Roman numerals I, II, III for parts, and Arabic numerals 1, 2, 3 for chapters. I would like it to say "Part I" rather than "I", and "Chapter 23" rather than "23". How can I change this consistently throughout the document?

Best Answer

You can use the tocloft package. A little example (feel free to adapt it according to your needs):

\documentclass{book}
\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}

\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}

EDIT: changed the "manual" names "Part" and "Chapter" to \partname and "\chaptername".

EDIT: changed to properly handle appendixes

Related Question