In this instance you're most likely interested in adjusting the number widths of all sectional units in the ToC, since they are usually set hierarchically. As such, a simple redefinition of the \numberline
macro suffices:
\usepackage{tocloft}% http://ctan.org/pkg/tocloft
\makeatletter
\renewcommand{\numberline}[1]{%
\@cftbsnum #1\@cftasnum~\@cftasnumb%
}
\makeatother
The above removes the former \hb@xt@\@tempdima{...}
construction, which sets the number inside a fixed-width box, left-aligned. In fact, the original definition made by tocloft
is:
\renewcommand{\numberline}[1]{%
\hb@xt@\@tempdima{\@cftbsnum #1\@cftasnum\hfil}\@cftasnumb}
Here's a minimal working example showing the result:
\documentclass{report}
\usepackage{tocloft}% http://ctan.org/pkg/tocloft
\makeatletter
\renewcommand{\numberline}[1]{%
\@cftbsnum #1\@cftasnum~\@cftasnumb%
}
\makeatother
\begin{document}
\tableofcontents
\chapter{A chapter}\section{A section}
\setcounter{chapter}{11}
\chapter{A chapter}\section{A section}
\setcounter{chapter}{122}
\chapter{A chapter}\section{A section}
\setcounter{chapter}{1233}
\chapter{A chapter}\section{A section}
\setcounter{chapter}{12344}
\chapter{A chapter}\section{A section}
\end{document}
Since the original definition left a "dynamic" gap between the number and the title, I've forced it to be ~
in my example. You can modify that to whatever length you're interested in (\quad
, \hspace*{2em}
, ...).
Note that this modification has to be inserted before calling \tableofcontents
.
Simply add these lines to your preamble
\renewcommand{\cftsecafterpnum}{\hspace*{7.5em}}
\renewcommand{\cftsubsecafterpnum}{\hspace*{7.5em}}
and adjust 7.5em
to your needs.
MWE
\documentclass[12pt]{article}
\usepackage{setspace, tocloft}
%Modifies line spacing of the ToC
\setlength\cftparskip{-1.2pt}
\setlength\cftbeforesecskip{1.3pt}
\setlength\cftaftertoctitleskip{2pt}
\renewcommand{\cftsecafterpnum}{\hspace*{7.5em}}
\renewcommand{\cftsubsecafterpnum}{\hspace*{7.5em}}
%Makes dots after sections/subsections: Sections 1., 2.1., etc
\makeatletter
\renewcommand{\@seccntformat}[1]{\csname the#1\endcsname.\quad}
\makeatother
%Makes the dots (above) appear in ToC
\let \savenumberline \numberline
\def \numberline#1{\savenumberline{#1.}}
\begin{document}
\tableofcontents
\begin{section}{Section 1}
\begin{subsection}{Section 1.1}\end{subsection}
\begin{subsection}{Section 1.2}\end{subsection}
\end{section}
\begin{section}{Section 2}\end{section}
\end{document}
Output
A remark
If you want to add dots after sections and subsections numbers, you can use
\renewcommand{\cftsecaftersnum}{.}
\renewcommand{\cftsubsecaftersnum}{.}
instead of
\let \savenumberline \numberline
\def \numberline#1{\savenumberline{#1.}}
Best Answer
The following example code contains the necessary redefinitions:
However, take into account the following remark conatined in the documentation of
classicthesis
: