7

I'm using tocloft package to format Table of Contents.

The problem is reproduced in the following minimal working example. The indentation level of Appendix A is incorrect. But the command \setlength{\cftchapnumwidth}{30mm} doesn't work for the second time.

Here is the text version of the picture:


 Contents

 Chapter 1. My chapter name bla bla bla bla bla bla bla bla bla
            bla bla bla bla bla bla bla bla bla bla bla bla         2

 Appendix A:  My appendix name bla bla bla bla bla bla bla bla 
            bla bla bla bla bla bla bla bla bla bla bla bla         3
            ^ $

 ^ - incorrect indentation level (25 mm)
 $ - correct indentation level (30 mm)

This picture was produces by the following code.

\documentclass[12pt,openany,oneside,a4paper]{book}
\usepackage[titles]{tocloft}

\begin{document}

\setlength{\cftchapnumwidth}{25mm} %25mm have been chosen manually

\tableofcontents

\chapter*{Chapter 1. My chapter name bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla}
\addcontentsline{toc}{chapter}{Chapter 1. My chapter name bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla}

Chapter text.

\appendix

\setlength{\cftchapnumwidth}{30mm}  %This command doesn't work!

\chapter*{Appendix A: My appendix name bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla}
\addcontentsline{toc}{chapter}{Appendix A: My appendix name bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla}

Appendix Text.

\end{document}

I have no idea how to patch the code.

Werner
  • 603,163
Ivan Bychkov
  • 731
  • 1
  • 6
  • 13
  • \setlength{\cftchapnumwidth}{30mm} has to go before \tableofcontents, it is there it is used not within the text itself. Regarding your manual adding Chapter, the memoir class can do this automatically plus memoir has the tocloft features build in. – daleif Mar 07 '12 at 23:07
  • Before addressing the ToC issue, I have a question: it's not clear to me why you use \chapter* and \addcontentsline; why don't you simply use \chapter? – Gonzalo Medina Mar 07 '12 at 23:08
  • 1
    @Gonzalo, actually it's a model example. In the real file I start each appendix with \Appendix command described in the preamble. \Appendix calls: \chapter*{#1} and \addcontentsline{toc}{chapter}{Appendix \thechapter: #1}. Since I'm new to latex, I'm happy that it works :) – Ivan Bychkov Mar 14 '12 at 16:37

1 Answers1

4

Change the line after \appendix into

\addtocontents{toc}{\protect\setlength{\cftchapnumwidth}{30mm}}

after \appendix, so that the directive will be issued at the correct time, when typesetting the table of contents.

egreg
  • 1,121,712