GeneralIndent Problem in Table of Contents

LaTeX specific issues not fitting into one of the other forums of this category.
perl0101
Posts: 8
Joined: Sat Aug 29, 2009 3:59 am

Indent Problem in Table of Contents

Post by perl0101 »

Hello everyone,

I met one problem with TableOfContent. The indent of the first level is not correct. For example, Chapter 1 Introduction is overlap. I guess it is the problem of \numwidth. But how to solve it. Please help. Thanks.

Image

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

perl0101
Posts: 8
Joined: Sat Aug 29, 2009 3:59 am

Re: Indent Problem in Table of Contents

Post by perl0101 »

The relevant code in .cls I find is the following. I would like to get suggestions to overcome this problem. Thanks.

\ifnum \c@secnumdepth >\m@ne
\refstepcounter{chapter}%
\typeout{\@chapapp\space\thechapter.}%
\addcontentsline{toc}{chapter}%
{\protect\numberline{\@chapapp\space\thechapter}#1}%
\else
\addcontentsline{toc}{chapter}{#1}%
\fi
\chaptermark{#1}%
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
\if@twocolumn
\@topnewpage[\@makechapterhead{#2}]%
\else
\@makechapterhead{#2}%
\@afterheading
\fi%
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Indent Problem in Table of Contents

Post by gmedina »

Hi,

this is analogous to the situation with the LoF, LoT that you asked in
this other thread.

All you have to do is to increase the length \cftchapnumwidth to avoid overlaping and to use
\cftchappresnum to include the word "Chapter":

Code: Select all

\documentclass{book}
\usepackage{tocloft}

\newlength\mylength
\settowidth\mylength{Chapter\hspace*{1em}}

\addtolength\cftchapnumwidth{\mylength}

\renewcommand\cftchappresnum{Chapter }

\begin{document}
\tableofcontents
\clearpage

\chapter{Test chapter}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
perl0101
Posts: 8
Joined: Sat Aug 29, 2009 3:59 am

Re: Indent Problem in Table of Contents

Post by perl0101 »

I sovle the problem by adding :

\renewcommand{\cftchapnumwidth}{6em}

from one previous post here.
oyvindhauge
Posts: 3
Joined: Thu Sep 10, 2009 10:23 am

Indent Problem in Table of Contents

Post by oyvindhauge »

Thanks to gmedina I have been able to solve most my lof/lot problems, however there is one thing which I have been unable to solve.

When table/figure captions span more than one line in the lot/lof the indent is not how I want it. This is more or less what I have today:

Code: Select all

Figure 1.2  This is a table with
       a long caption ......... 2


What I would like to see is something like this:

Code: Select all

Figure 1.2  This is a table with
            a long caption .... 2
In other words I would like the text on the second line to be aligned directly below the text on the first line.

I have tried both commands below without any luck.

Code: Select all

\addtolength\cftfignumwidth{}
\cftsetindents{figure}{}{}
I have tried also revised the documentation for tocloft, this forum, and Google but unfortunately without any luck. I apologize if I have overlooked the obvious. Could anyone please share their insights?
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Indent Problem in Table of Contents

Post by gmedina »

Hi,

can you please post a minimal working example showing your current settings for the LoF?
1,1,2,3,5,8,13,21,34,55,89,144,233,...
oyvindhauge
Posts: 3
Joined: Thu Sep 10, 2009 10:23 am

Indent Problem in Table of Contents

Post by oyvindhauge »

Yes of course. Sorry for not doing it in the first place. I am new to the forum.

Code: Select all

\documentclass{article}
\usepackage{tocloft}
\renewcommand{\cfttabfont}{Table }
\begin{document}
\listoftables					
\begin{table}
\begin{tabular}{l} 
\textbf{Header of the table}\\
TEST \\
\end{tabular}
\caption{Some long, very long test text which should span at least one line in the list of tables}
\end{table}
\end{document}
PS! Thanks for your rapid response.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Indent Problem in Table of Contents

Post by gmedina »

Hi,

simply apply some of the suggestions I made to perl0101 in this thread and in this other one. An example:

Code: Select all

\documentclass{article}
\usepackage{tocloft}

\newlength\mylength
\settowidth\mylength{Table}

\addtolength\cfttabnumwidth{\mylength}
\renewcommand\cfttabpresnum{Table }

\begin{document}
\listoftables               

\begin{table}[!ht]
  \centering
  \rule{4cm}{3cm}% to simulate a table
  \caption{Some long, very long test text which should span at least one line in the list of tables}
  \label{tab:test}
\end{table}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
oyvindhauge
Posts: 3
Joined: Thu Sep 10, 2009 10:23 am

Indent Problem in Table of Contents

Post by oyvindhauge »

Thanks a lot for your help. I am really sorry for overlooking your previous advice on the topic. I even read both threads.

I mixed up the two possibilities below after looking at this thread and this comment. I guess the first one (the one you suggested) is better.

Code: Select all

\renewcommand\cfttabpresnum{Table } % Works the way I wanted
\renewcommand{\cfttabfont}{Table } % Does not work the way I wanted
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Indent Problem in Table of Contents

Post by gmedina »

oyvindhauge wrote:Thanks a lot for your help.
You're welcome.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply