应明白章节标题命令的一个潜在作用(虽然lshort中没有明讲,但基本能自悟到):创建编号的同时给编号计数加1。因此,没有必要在正文区中使用多余的\setcounter,\addtocounter
。
另外,\part
的编号默认为罗马数字样式,该样式没有计数为0的形式吧...这里为方便表示,我修改了\part,\section
的编号样式,您可再另外调整:
\renewcommand{\thepart}{\arabic{part}} % 阿拉伯数字形式
\renewcommand{\thechapter}{\alph{chapter}} % 小写字母形式
由于需求为“第一个\part
的计数为0”,因此在“第一个\part
之前将其计数设为-1:,由此\part
被执行时其计数加1刚好等于0:
\setcounter{part}{-1}
MWE:
\documentclass{book}
\counterwithout{subsection}{section} %为了实现其他排版要求
\renewcommand{\thepart}{\arabic{part}}
\renewcommand{\thechapter}{\alph{chapter}}
\usepackage{hyperref}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\setcounter{part}{-1}
\part{zeroth part}
\part{first part}
\chapter{first chapter}
\part{second part}
\chapter{second chapter}
\chapter{third chapter}
\backmatter
\end{document}
效果:
无论哪种编译选项,pdf正常、书签正常。
而且别忘了:使用hyperref宏包时,除latexmk以外都需编译2次。
问 pdflatex编译下,自定义part计数器为什么导致hyperref生成的书签层级出错?