如何实现\chapter随\part的编号增加而清零重新编号 MWE如下: ``` \documentclass{ctexbook} \usepackage{hyperref} \begin{document} \part{} \chapter{} \part{} \chapter{} \end{document} ``` 想实现这样的效果 ``` 第一部分 第一章 第二部分 第一章 ```

2 回答2

1
建议给 ctexbook 添加 openany 选项减少空页。 解决方法: ```tex \documentclass[openany]{ctexbook} \usepackage{hyperref} \usepackage{chngcntr} \counterwithin{chapter}{part} \begin{document} \part{Hello} \chapter{Elegant\LaTeX{}} \part{World} \chapter{Program} \end{document} ``` 和另外一种方法 ```tex \makeatletter \@addtoreset{chapter}{part} \makeatother ``` 是等价的,推荐前者。 参考:[How to reset chapter and section counter with \part](https://tex.stackexchange.com/questions/54383/how-to-reset-chapter-and-section-counter-with-part)

回答: 2019-09-16 22:08

如果是 ElegantBook 模板,请使用 ```tex \makeatletter \@addtoreset{chapter}{part} \makeatother ``` 原因是模板修改过 `\partname`,导致两种方法并不等价。
  • 回复 Carcino : 好的,谢谢! – ddswhu 2019-09-19 21:17 回复
  • 2018 年 3 月 8 日,latex2e 添加了命令 \counterwithin 和 \counterwithinout,所以对较新版本的 latex2e,无需加载 chngcntr 宏包了。 – Carcino 2019-09-16 23:18 回复
  • 这个简洁,我没注意到\part的计数器就是part – TvZ8lPRVOT8C 2019-09-16 22:17 回复
0
\part 是-1层次的,编号不对下一层产生影响,需要自定义一个计数器,然后让chapter或者section绑定在此计数器上 ```tex \documentclass{ctexbook} \usepackage{titlesec}%%章节格式设置 \usepackage{zhnumber}%%中文数字 \usepackage{amsmath} \newcounter{mycnt} \setcounter{mycnt}{1} \titleformat{\part}{\centering\huge\bfseries}{第\zhnumber{\themycnt}部分\stepcounter{mycnt}}{1em}{} \numberwithin{chapter}{mycnt} \begin{document} \tableofcontents \part{} \chapter{} \part{} \chapter{} \end{document} ```

你的回答

请登录后回答

你的回答将会帮助更多人,请务必认真回答问题。