The tocloft package

Controls fonts, indents, dot leaders and spacing in the table of contents, list of figures and list of tables through lengths and commands named \cft....

Loading the package

\usepackage{tocloft}

The standard classes define each line of the table of contents in internal commands such as \l@section. tocloft replaces them with named settings. The name contains the entry type: chap, sec, subsec, fig, tab. So \cftsecfont is the font of a section entry and \cftsecpagefont the font of its page number.

Commands are changed with \renewcommand, lengths with \setlength.

Main commands

\renewcommand{\cftsecfont}{\sffamily}Font of the section entries; \cftsecpagefont sets the font of their page numbers.
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}Dot leaders for section entries, which article sets without dots.
\setlength{\cftsecnumwidth}{3em}Width reserved for the section number. Raise it when a number such as 10.12 touches the title.
\cftsetindents{subsection}{1.5em}{3em}Sets indent and number width of one entry type in one step.
\setlength{\cftbeforesecskip}{4pt}Vertical space above each section entry.
\renewcommand{\cfttoctitlefont}{\Large\bfseries}Font of the heading "Contents"; \cftloftitlefont and \cftlottitlefont apply to the other two lists.
\usepackage[titles]{tocloft}Leaves the headings of the lists as the class sets them.

Complete example

\documentclass{article}
\usepackage{tocloft}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cftsecfont}{\sffamily\bfseries}
\renewcommand{\cftsecpagefont}{\sffamily}
\setlength{\cftbeforesecskip}{4pt}
\begin{document}
\tableofcontents
\section{Introduction}
Text of the first section.
\subsection{Background}
Text of the subsection.
\section{Method}
Text of the second section.
\end{document}
Result
The compiled example

Open in the editor

Compiled with pdfLaTeX from TeX Live 2023. Tools run in this order: pdflatex → pdflatex.

Pitfalls

Related pages