答案1
我尝试通过修补\subsection
来获取新命令,从而解决这个问题\mysubsection
。然后您可以使用它\mysubsection
来获取不会出现在内容中的编号部分。
\documentclass{article}
\usepackage{xpatch}
\makeatletter
\let\my@sect\@sect
\let\my@startsection\@startsection
\let\mysubsection\subsection
\xpatchcmd{\my@sect}{%
\addcontentsline{toc}{#1}{%
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}%
} {%
} {} {}
\xpatchcmd{\my@startsection}{\@sect}{\my@sect}{}{}
\xpatchcmd{\mysubsection}{\@startsection}{\my@startsection}{}{}
\makeatother
\begin{document}
\tableofcontents
\section{test}
\subsection{test}
\mysubsection{test}
\subsection{test}
\section{test}
\subsection{test}
\mysubsection{test}
\subsection{test}
\end{document}