Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
AFAIR tocloft can do this –  daleif May 10 '11 at 11:20
    
@daleif: Can you not port the memoir toc setup to toclof. It does not look if Peter Wilson is going to get around to do that. This is a very old FAQ and there are not realy a good solution besides memoir and amsbook. –  Danie Els May 10 '11 at 13:50
add comment

1 Answer

up vote 6 down vote accepted

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

share|improve this answer
1  
And what about appendixes? –  Danie Els May 10 '11 at 12:56
    
@Danie Els: you are right; I've edited my code to use \partname and \chaptername which should handle appendices if the \backmatter command is used. –  Gonzalo Medina May 10 '11 at 13:04
    
Nope, you have redefine \cftchappresnum inside a \addtocontents. This causes a new set of problems when you use \include because of latex's immediate and delayed write mechanisms. The only foolproof solution is memoir or amsbook –  Danie Els May 10 '11 at 13:25
    
Typo in comment. Should have been: you have to redefine .... –  Danie Els May 12 '11 at 1:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.