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'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.

share|improve this question
    
\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 7 '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 7 '12 at 23:08
    
@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 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
This works! Thanks a lot. –  Ivan Bychkov Mar 7 '12 at 23:08

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.