2

How do I increase the spacing between the numbering and the text in the table of contents? Note that I am using the article class and use \addcontentsline{toc}.

enter image description here

Code:

\documentclass[12pt]{article}

\newcounter{chapternum}
\newcounter{examplenum}

\newcommand{\example}{\stepcounter{examplenum} \noindent{\large{\color{Red}{Example \theexamplenum: }}}\addcontentsline{toc}{subsubsection}{Example \theexamplenum}}
\renewcommand\thesection{\thechapternum.\arabic{section}}
\renewcommand\thesubsection{\thesection.\arabic{subsection}}

\begin{document}
\stepcounter{chapternum}

\tableofcontents %Ignore the page numbers; the picture is a screenshot from my document and this code is a MWE.

\section{Sets}

\subsection{Introduction to Sets}

\subsection{Union and Intersection}

\example

\subsection{Special Sets}

\subsection{Interval Notation}

\example

\end{document}
0

1 Answer 1

2

You can use tocloft and adjust these

\setlength{\cftsecnumwidth}{2em}          %% adjust
\cftsetindents{subsection}{2em}{3em}      %% adjust
\cftsetindents{subsubsection}{5em}{4em}   %% adjust

Here, \cftsecnumwidth is the width of the box in which section numbers are typeset. From tocloft manual (page 10):

enter image description here

Code

\documentclass[12pt]{article}
\usepackage{xcolor}
\usepackage{tocloft}
\newcounter{chapternum}
\newcounter{examplenum}

\newcommand{\example}{\stepcounter{examplenum} \noindent{\large{\color{red}{Example \theexamplenum: }}}\addcontentsline{toc}{subsubsection}{Example \theexamplenum}}
\renewcommand\thesection{\thechapternum.\arabic{section}}
\renewcommand\thesubsection{\thesection.\arabic{subsection}}

\setlength{\cftsecnumwidth}{2em}
\cftsetindents{subsection}{2em}{3em}
\cftsetindents{subsubsection}{5em}{4em}
\begin{document}
\stepcounter{chapternum}

\tableofcontents %Ignore the page numbers; the picture is a screenshot from my document and this code is a MWE.

\section{Sets}

\subsection{Introduction to Sets}

\subsection{Union and Intersection}

\example

\subsection{Special Sets}

\subsection{Interval Notation}

\example

\end{document}

enter image description here

Not the answer you're looking for? Browse other questions tagged .