如何隐藏LaTeX目录章节编号并重置小节编号链?
解决LaTeX article类中断开章节编号链的问题
你的核心问题是小节编号延续了之前的章节计数,要让Introduction小节显示为1.1,只需重置章节计数器即可,具体修改如下:
修改后的代码
\documentclass{article} \begin{document} \tableofcontents \newcommand{\fakesection}[1]{% \par\refstepcounter{section}% Increase section counter \sectionmark{#1}% Add section mark (header) \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}% Add section to ToC %Add more content here, if needed. } % 重置section计数器为0,确保后续section从1开始 \setcounter{section}{0} \fakesection{Chapter 1: Introduction} \begin{center} \huge Chapter 1 \\ \huge Introduction \end{center} \subsection{Introduction} Hello welcome. \end{document}
原理说明
- LaTeX的
article类中,subsection的编号格式是\thesection.\arabic{subsection},完全依赖于section计数器的当前值。 - 你之前的
section计数器已累计到7,执行\refstepcounter{section}后变成8,因此小节编号显示为8.1。 - 通过
\setcounter{section}{0}将计数器清零,再执行\refstepcounter{section}让section变为1,对应的小节自然会从1.1开始计数,相当于断开了和之前章节的编号关联。
如果之后需要再次断开编号链,只需在新章节前重复使用\setcounter{section}{0}即可。
内容的提问来源于stack exchange,提问作者Mzi
相关产品推荐
相关产品推荐

