我想book
在目录中显示类文档前言部分中某些章节的节。问题是前言中的所有章节都编号为 0,因此它们的节的编号为 0.1、0.2。我想隐藏数字,但在目录中显示节标题。我该如何实现?
例子:
CONTENTS
% Front Matter
Preface
How to use the book
Book organization
Glossary
% Main Matter
Chapter 1 Test Chapter 1
1.1 Test section 1
1.2 Test section 2
Chapter 2 Test Chapter 2
2.1 Test section 1
2.2 Test section 2
答案1
您可以使用它\setcounter{secnumdepth}{0}
来获取前言中的未编号章节以及\setcounter{secnumdepth}{2}
获取正文中的编号部分、章节、节和小节:
\documentclass{book}
\usepackage{blindtext}% only for dummy text
\usepackage{xpatch}
\xappto{\frontmatter}{\setcounter{secnumdepth}{0}}{}{}% unnumbered sections, subsections, subsubsections etc.
\xappto{\mainmatter}{\setcounter{secnumdepth}{2}}{}{}% numbered parts, chapters, sections, subsections
\begin{document}
\frontmatter
\tableofcontents
\chapter{Preface}
\chapter{How to use the book}
\section{Book organization}
\section{Glossary}
\mainmatter
\blinddocument
\blinddocument
\end{document}