LaTeX目录无法显示章节编号末尾圆点问题求助
解决LaTeX正文与目录章节编号格式不一致的问题
我来帮你梳理下问题并给出解决方案~
问题根源
你遇到的\thechapter未定义错误,核心原因是你使用的是article文档类——这个类里根本没有chapter计数器(只有section、subsection、subsubsection这些层级),所以你尝试重定义\thechapter肯定会报错。另外你重复加载了listings包和重复调用\sectiondot{subsection},这些冗余代码也可以清理掉。
你的需求是:
- 正文章节编号:
1.、1.1.、1.1.1.(带末尾点) - 目录章节编号:
1、1.1、1.1.1(不带末尾点)
不需要依赖secdot包,我们可以通过重定义编号命令和目录格式来实现这个效果。
解决方案:完整修改代码
下面是调整后的完整代码,我会标注关键修改点:
\documentclass[11pt, a4paper, twoside]{article} \usepackage{listings, lstautogobble} \usepackage{ragged2e} \usepackage{times} \usepackage[toc,page]{appendix} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage{geometry} % 补全缺失的geometry包 \geometry{a4paper, left=30mm, top=25mm, bottom=25mm, right=20mm } \usepackage{tocloft} % 用于自定义目录格式 \makenomenclature \setlength{\parindent}{0.5 cm} \renewcommand{\baselinestretch}{1.15} % -------------------------- 关键修改:编号格式定义 -------------------------- % 1. 正文里的章节编号(带末尾点) \renewcommand{\thesection}{\arabic{section}.} \renewcommand{\thesubsection}{\thesection\arabic{subsection}.} \renewcommand{\thesubsubsection}{\thesubsection\arabic{subsubsection}.} % 2. 目录里的章节编号(不带末尾点) \renewcommand{\cftsecnumformat}[1]{\arabic{section}\quad} \renewcommand{\cftsubsecnumformat}[1]{\arabic{section}.\arabic{subsection}\quad} \renewcommand{\cftsubsubsecnumformat}[1]{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}\quad} % --------------------------------------------------------------------------- \pagenumbering{roman} \begin{document} \setboolean{@twoside}{false} \begin{figure}[H] \begin{center} \includegraphics[width=14cm,height=15cm,keepaspectratio]{./thesis-frontpagedesign} \end{center} \end{figure} \begin{center} \tableofcontents \listoffigures \end{center} \section{Introduction} % 这里可以添加你的正文内容 \subsection{Subsection Example} Some text for subsection. \subsubsection{Subsubsection Example} Some text for subsubsection. \end{document}
代码说明
- 补全缺失的包:你之前使用了
\geometry命令但没加载geometry包,这会导致编译错误,我已经补上了。 - 正文编号定义:通过
\renewcommand{\thesection}等命令,让每个层级的编号末尾都带上点。 - 目录编号定义:借助
tocloft包的\cftsecnumformat系列命令,重新定义目录中各层级编号的输出格式,去掉末尾的点。 - 清理冗余代码:移除了重复的
\usepackage{listings}和\sectiondot{subsection}调用。
这样编译后,正文里的章节编号会带末尾点,而目录里的编号会自动去掉末尾点,完全符合你的需求。
内容的提问来源于stack exchange,提问作者misi06
相关产品推荐
相关产品推荐

