使用 \addcontentslin{toc} 增加目录间距

使用 \addcontentslin{toc} 增加目录间距

如何增加目录中编号和文本之间的间距?请注意,我正在使用类article并使用\addcontentsline{toc}.

在此处输入图片描述

代码:

\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}

答案1

您可以使用tocloft和调整这些

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

\cftsecnumwidth是排版章节编号的框的宽度。摘自tocloft手册(第 10 页):

在此处输入图片描述

代码

\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}

在此处输入图片描述

相关内容