Without any packages:
In the standard documentclass without the influence of a package like titletoc
you have to redefine the command \l@subsection
. In the file book.cls
you find the following settings:
\newcommand*\l@section{\@dottedtocline{1}{1.5em}{2.3em}}
\newcommand*\l@subsection{\@dottedtocline{2}{3.8em}{3.2em}}
\newcommand*\l@subsubsection{\@dottedtocline{3}{7.0em}{4.1em}}
\newcommand*\l@paragraph{\@dottedtocline{4}{10em}{5em}}
\newcommand*\l@subparagraph{\@dottedtocline{5}{12em}{6em}}
The command \@dottedtocline
expects the following parameters:
\renewcommand{\l@<typ>}{\@dottedtocline{<level>}%
{<indentation>}%
{<numwidth>}}
To reduce the indentation of subsection
you can do:
\makeatletter
\renewcommand*\l@subsection{\@dottedtocline{2}{1.8em}{3.2em}}
\makeatother
Example:
\documentclass{book}
\makeatletter
\renewcommand*\l@subsection{\@dottedtocline{2}{1.8em}{3.2 em}}
\makeatother
\begin{document}
\tableofcontents
\chapter{foo}
\section{bar}
\subsection{foobar}
\end{document}
The method is equal for floating environments. The standard class book.cls
provides \l@figure
and and \l@table
with the following settings:
\newcommand*\l@figure{\@dottedtocline{1}{1.5em}{2.3em}}
\let\l@table\l@figure
Package titletoc
By using the package titletoc you can set the indentation using \dottedcontents
:
\dottedcontents{<section>}[<left>]{<above-code>}
{<label width>}{<leader width>}
Example
\documentclass{book}
\usepackage{titletoc}
\dottedcontents{subsection}[5.5em]{}{3.2em}{1pc}
\begin{document}
\tableofcontents
\chapter{foo}
\section{bar}
\subsection{foobar}
\end{document}
The argument <section>
can be somewhat irritating. The argument allows the name without a leading backslash so that figure
and table
are allowed, too.
Package tocloft
The package tocloft offers more than the following setting. The indentation is set by the length \cftXindent
. The X
stands for:
- part for
\part
titles
- chap for
\chapter
titles
- sec for
\section
titles
- subsec for
\subsection
titles
- subsubsec for
\subsubsection
titles
- para for
\paragraph
titles
- fig for
figure \caption
title
- tab for
table \caption
titles
Example:
\documentclass{book}
\usepackage{tocloft}
\setlength{\cftsubsecindent}{2em}
\begin{document}
\tableofcontents
\chapter{foo}
\section{bar}
\subsection{foobar}
\end{document}
KOMA-Script
With a recent version of KOMA-Script one can use \RedeclareSectionCommand
to change the entries in the table of contents as well. You can use that for all defined sectioning commands.
\documentclass{scrbook}
\RedeclareSectionCommand[%
tocindent=9em,tocnumwidth=7em,]{subsection}
\begin{document}
\tableofcontents
\chapter{foo}
\section{bar}
\subsection{foobar}
\end{document}
The modification of figure
and table
is equal to the standard class and defined as follow:
\newcommand*\l@figure{\@dottedtocline{1}{1.5em}{2.3em}}
\let\l@table\l@figure
Package tocstyle (link in German)
With recent versions of KOMA-Scrpt, many parts of tocstyle
are unneeded. It will be completely incorporated in KOMA-Script in the future.
To manipulate the toc (or other list of ...) in combination with a class of the KOMA bundle you should use the package tocstyle
. The package is part of the KOMA bundle but with a separate documentation. The influence of the indentation is given indirectly by entryhook
which can be set by \settocfeature
One of the benefits oftocstyle
is the automatic calculation of the needed indentation.
Example:
\documentclass{scrbook}
\usepackage{tocstyle}
\usetocstyle{KOMAlike}
\settocfeature[toc][2]{entryhook}{\protect\hspace*{-1.5em}\nobreakspace}
\begin{document}
\tableofcontents
\chapter{foo}
\section{bar}
\subsection{foobar}
\end{document}
You show the chapter code but not the part code, the dots come ffom this bit of \l@chapter
\leaders\hbox{$\m@th\mkern\@dotsep mu\hbox{.}\mkern\@dotsep mu$}
\hfil
If you look in your class file (or if it inputs one of the standard classes) you will find \ definition of \l@part
that just has \hfil
(white space) rather than the leaders. eg \l@part
in article has
\large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
putting the \leaders line between #1
(the chapter title) and the \hfil
will make the hfill work by repeating the dots rather than just using space.
like so:
\documentclass{uiucthesis}
\makeatletter
\renewcommand*\l@part[2]{%
\ifnum \c@tocdepth >-2\relax
\addpenalty{-\@highpenalty}%
\addvspace{2.25em \@plus\p@}%
\setlength\@tempdima{3em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
{\leavevmode
\large \bfseries #1%
\leaders\hbox{$\m@th\mkern\@dotsep mu\hbox{.}\mkern\@dotsep mu$}%
\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
\nobreak
\global\@nobreaktrue
\everypar{\global\@nobreakfalse\everypar{}}%
\endgroup
\fi}
\makeatother
\begin{document}
\tableofcontents
\part{the first}
\chapter{foo}
\section{hmmm}
aaa
\section{hmmm}
bbb
\end{document}
Best Answer
For dotted TOC lines, standard LaTeX and also KOMA-Script use the internal macro
\@dotsep
which specifies that space in mu. Its original value is 4.5.You could adjust it this way: