来自群主的mcmthesis模板。请务必保证TeXLive2024编译。
下面的mwe:
\documentclass{mcmthesis}
\mcmsetup{tstyle=\color{black}\bfseries,
tcn = 1234567, problem = S, sheet = true,
titleinsheet = true, keywordsinsheet = true,
titlepage = false, abstract = true}
\setlength{\headheight}{13.6pt}
\usepackage{lastpage}
% \usepackage{tocloft}
% \tocloftpagestyle{main}
% \setlength{\cftbeforesecskip}{10pt}
% \setlength{\cftbeforesubsecskip}{5pt}
\begin{document}
\tableofcontents
\clearpage
\section{Fisrt}
\subsection{Fisrt}
\subsection{Second}
\subsection{Third}
\subsection{Four}
\subsection{Five}
\section{Second}
\subsection{Fisrt}
\subsection{Second}
\subsection{Third}
\subsection{Four}
\subsection{Five}
\section{Third}
\subsection{Fisrt}
\subsection{Second}
\subsection{Third}
\subsection{Four}
\subsection{Five}
\section{Four}
\subsection{Fisrt}
\subsection{Second}
\subsection{Third}
\subsection{Four}
\subsection{Five}
\end{document}默认样式效果如图1:

现在希望修改ToC的间距,如果使用tocloft宏包的设置:
\usepackage{tocloft}
\tocloftpagestyle{main}
\setlength{\cftbeforesecskip}{10pt}
\setlength{\cftbeforesubsecskip}{5pt}注意其中fancystytle=main的定义在mcmthesis.cls中定义为:
%Line107
\fancypagestyle{main}{
\fancyhf{}
\lhead{\small\sffamily \team}
\rhead{\small\sffamily Page \thepage\ of \pageref{LastPage}}
}
\pagestyle{main}同时tocloft默认行为将调用为\tocloftpagestyle{plain},这会导致和图1中mcmthesis.cls设置的字体,间距等配置被覆盖,如下图2:

这虽然可以使用tocloft提供的强大命令再次设置,但是这一过程很不优雅,而且确定原始图一的字体配置是比较困难的,感觉应该从article.cls更底层的\tableofcontents定义进行修改才是better practice.
另附mcmthesis.cls中定义:
\renewcommand\tableofcontents{%
\centerline{\normalfont\Large\bfseries\sffamily\contentsname
\@mkboth{%
\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
\vskip 5ex%
\@starttoc{toc}%
}以及article.cls中定义:
\newcommand\tableofcontents{%
\section*{\contentsname
\@mkboth{%
\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
\@starttoc{toc}%
}总而言之,希望保持图一的其他设置(除了ToCskip),同时修改ToC行距的最佳实践(个人觉得应该从更底层的mcmthesis.cls中的\renewcommand\tableofcontents入手,避免tocloft复写原有设置)。
默认情况下,LaTeX 的目录由 l@<title> 输出,<title> 就是 chapter section 这些,其中 part chapter section 都定义了自己的 l@..,而 subsection 及其子标题都使用 \@dottedtocline,区别是设置不同的参数。查看 mcmthesis 2024/01/22 v6.3.3 源码发现,它并没有修改这一行为。
因此只需在导言区加上
\makeatletter
\@namedef{@level1@space}{10pt} % section
\@namedef{@level2@space}{10pt} % subsection
\@namedef{@level3@space}{0pt} % subsubsection
\long\def\sectionvspace#1{\addvspace{\@nameuse{@level1@space}}}
\patchcmd\l@section{\addvspace}{\sectionvspace}{}{\ERR} % section
\long\def\dottedvspace#1#2#{\nointerlineskip \vskip-\parskip \vskip\@nameuse{@level#1@space}\relax}
\patchcmd\@dottedtocline{\vskip}{\dottedvspace{#1}}{}{\ERR} % subsection
\makeatotherself comment...
其实差距就是 \centerline{\normalfont\Large\bfseries\sffamily\contentsname
[editted here]所谓的tocloft设置“比较困难”也并没有多困难,如下代码:
\documentclass{mcmthesis}
\mcmsetup{tstyle=\color{black}\bfseries,
tcn = 1234567, problem = S, sheet = true,
titleinsheet = true, keywordsinsheet = true,
titlepage = false, abstract = true}
\setlength{\headheight}{13.6pt}
\usepackage{lastpage}
\usepackage{tocloft}
\tocloftpagestyle{main}
\renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries\sffamily}
\renewcommand{\cftaftertoctitle}{\hfill}
\setlength{\cftbeforesecskip}{10pt}
\setlength{\cftbeforesubsecskip}{5pt}
\begin{document}
\tableofcontents
\clearpage
\section{Fisrt}
\subsection{Fisrt}
\subsection{Second}
\subsection{Third}
\subsection{Four}
\subsection{Five}
\section{Second}
\subsection{Fisrt}
\subsection{Second}
\subsection{Third}
\subsection{Four}
\subsection{Five}
\section{Third}
\subsection{Fisrt}
\subsection{Second}
\subsection{Third}
\subsection{Four}
\subsection{Five}
\section{Four}
\subsection{Fisrt}
\subsection{Second}
\subsection{Third}
\subsection{Four}
\subsection{Five}
\end{document}这便与图一(几乎)一模一样了...

但是这一实现过程令人很不舒服,从代码整体实现逻辑上看更合理的工作流是在更底层实现,而不是多个工具互相遮蔽。
是的是的,我的问题实际上是想问:
sources2e中目录控制的宏是哪些(戳手手)结合您的解释来看,我找到了此处代码
patch的代码位于article.cls的528~544行,如下:同时结合
\@namedef定义以及
\@dottedtocline的原始定义您提供的
patch结合上面的信息是可以理解的,谢谢您的帮助!