# TOC Text - numbers alignment

I am using \tableofcontents to create TOC in my document. however it is appearing as shown in the image. As the numbers increase the gap between the number and text is reducing.

Thanks for your help Aku

You can use the tocloftpackage, e.g.

\documentclass{book}
\usepackage{tocloft}
\setlength{\cftchapnumwidth}{3em}
\begin{document}
\tableofcontents
\chapter{Lorem}
\setcounter{chapter}{9}
\chapter{Ipsum}
\setcounter{chapter}{99}
\chapter{Dolor}
\end{document}


The lengt \cftXnumwidth defines how wide the space for the number of X should be, where X is part (for \part), chap (for \ \chapter), sec (for \section) etc. See the tocloft manual for a complete list. Set this length to fit your needs.

• I get an error when including this package in an article: ! LaTeX Error: Command \c@lofdepth already defined. Or name \end... illegal, see p.192 of the manual. – CPBL Nov 18 '15 at 16:19
• When increasing cftchapnumwidth, one might want to also increase by the same amount cftsecindent and cftsubsecindent (in general, cftXindent for all lower levels), so that section numbers (etc.) keep starting below chapter titles as they do by default. tocloft doesn't document this, but the output looks odd (IMHO) otherwise. – Blaisorblade Jul 17 '17 at 4:10

You can use a package or simply redefine the section level command as follows:

\documentclass[11pt]{article}
\makeatletter
\def\l@section{\@dottedtocline{1}{1em}{2em}}
\makeatother
\usepackage{index}
\makeindex

\begin{document}
\tableofcontents

\section{One}
\section{Two}
\section{Three}
\end{document}


In the \def\l@section{\@dottedtocline{1}{1em}{2em}} change the 2em to suit. Here is the format of the \@dottedtocline{<level>}{<indent>}{<numwidth>}{<title>}{<page>}.

• I used your trick because tocloft completely remove all format of the toc. But with your command chapter in the toc are no longer written in bold. How can I fix this ? Maybe it is due to the fact that chapter is not a dotted toc line ? – Ger Sep 3 '12 at 10:14
• This was the only solution that worked for me, tocloft was causing many problems with hyperref and other errors impossible to decipher. I also implemented it correctly for sublevels, thanks! – Santiago Aug 18 '16 at 8:54
• It works fine, but TOC is no longer bolded. – reducing activity Mar 9 '17 at 11:44

tocloft is a bit incompatible with KOMA-classes. The KOMA-bundle provides an own package tocstyle, that can be used with the standard classes as well. You can change the appearance of the toc, the right width will be iterated over several latex runs.

\documentclass{book}
\usepackage[tocindentauto]{tocstyle}
\usetocstyle{standard}
\begin{document}
\tableofcontents
\chapter{Duck}
\setcounter{chapter}{9}
\chapter{Penguin}
\setcounter{chapter}{99}
\chapter{Platypus}
\end{document}


• This is solved it for me so easily! This is a great answer compared to those which depend specifically on which documentclass someone is using. And it didn't require mucking around in any TeX commands, and wound up automatically formatting the ToC better than I would have manually tried to fix it anyway. In short, the ease of use + compatibility of this answer with multiple documentclass's and packages (e.g. as opposed to tocloft which seems to always be recommended but breaks everything) make it really great, in my opinion. – hasManyStupidQuestions Apr 8 '20 at 2:10
• @hasmany tocstyle never came out of alpha state and is now considered obsolete by its developer. All its features are now incorporated into tocbasic. That works very well with the standard classes too. – Johannes_B Apr 8 '20 at 3:05
• I looked through chapter 15 ctan.math.washington.edu/tex-archive/macros/latex/contrib/… but I couldn't find the option for \setuptoc to automatically indent equivalent to the tocindentauto combined with usetocstyle{standard}. But I suppose I should ask that as a separate question if it becomes an issue (for now I will just use the obsolete package and hope I don't need to update soon). – hasManyStupidQuestions Apr 8 '20 at 3:18
• @hasmany Better ask the question now. It will help other users too. – Johannes_B Apr 8 '20 at 3:31
• There might even be a question already, but right now i only have my phone for browsing. – Johannes_B Apr 8 '20 at 3:32