如何使目录看起来像
Chapter 1
Part 1 Etude
1.1 introducion
1.2 Other title
Part 2 Something
1.3 title
1.4 title
Chapter 2
谢谢。
答案1
这应该能满足您的要求。它基于我之前的评论。我警告您,我一点也不喜欢这个,因为它可能会破坏很多其他东西……如果您要认真使用它,您真正应该做的是,基于report
,使用您喜欢的分段来创建您自己的文档类。
\documentclass{report}
\makeatletter
% Include the word "Chapter" in the TOC
\renewcommand*\l@chapter[2]{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@
\setlength\@tempdima{1.5em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \bfseries
\advance\leftskip\@tempdima
\hskip -\leftskip
\chaptername{} #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\penalty\@highpenalty
\endgroup
\fi}
% Parts are really sections, numbering is based on chapters
\let\c@section\relax
\newcounter{section}[chapter]
\renewcommand\thesection{Part \@arabic\c@section}
\renewcommand\section{\@startsection{section}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\normalfont\Large\bfseries}}
\renewcommand*\l@section{\@dottedtocline{1}{1.5em}{3.5em}}
\let\part\section
% Sections are really subsections, but their numbering is based on chapters
\let\c@subsection\relax
\newcounter{subsection}[chapter]
\renewcommand\thesubsection{\thechapter.\@arabic\c@subsection}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
{-3.25ex\@plus -1ex \@minus -.2ex}%
{1.5ex \@plus .2ex}%
{\normalfont\large\bfseries}}
\let\section\subsection
\let\l@newsubsection\l@subsection
%
\makeatother
\begin{document}
\tableofcontents
\chapter{One} Blah blah...
\part{Etude} Blah blah...
\section{Introduction} Blah blah...
\section{Other title} Blah blah...
\part{Something} Blah blah...
\section{Title} Blah blah...
\section{Title} Blah blah...
\chapter{Two} Blah blah...
\end{document}
答案2
使用titlesec
它很容易添加级别。
\documentclass{book}
\usepackage{titlesec}
\titleclass{\subchapter}{straight}[\chapter]
\newcounter{subchapter}[chapter]
\renewcommand{\thesubchapter}{\arabic{subchapter}}
\titleformat{\subchapter}[display]
{\LARGE\bfseries\filcenter}
{Part \thesubchapter}
{1ex}
{}
\titlespacing{\subchapter}{1ex}{0pt}{4ex plus 2ex minus 1ex}
\makeatletter
\let\l@subchapter\l@section
\let\l@section\l@subsection
\let\l@subsection\l@subsubsection
\makeatother
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{A title}
\subchapter{Study}
\section{Introduction}
\section{Other title}
\subchapter{Something}
\section{Title A}
\section{Title B}
\end{document}
我只是在目录中将章节降级为小节,将小节降级为小小节,为新级别腾出空间。
您可以轻松添加其他自定义设置。我的建议是“不要这样做”。
答案3
我建议的方法,无论出于何种意图和目的,都会重置\part
以使其表现得像的同义词\section
,并重新定义与节和小节相关的宏的属性,使它们符合以下编号方案:
- “部分”编号不包含“章节”编号作为前缀,并且
\part
不会增加或重置 的编号\subsection
。 - “小节”编号包含相关的“章节”编号作为前缀。
- A
\chapter
命令将\part
和\subsection
数字重置(为零)。
下面的代码实现了这一点,它还提供了命令来 (i) 自动将字符串“Part”添加到节标题和目录中的部分编号前面(以不影响创建交叉引用的能力的方式)和 (ii) 启用\subsubsection
-level 标题的编号,因为\section
-level 标题已被转移为“部分”。您可能希望摆弄目录中各个条目的缩进级别。
最后,请注意,因为\part
已将其设置为类似行为\section
,并且因为\section
相关命令具有不是已被禁用,您可以在文档中使用\part
或来创建“部分级”标题。\section
\documentclass{report}
% Undefine the existing \part and \thepart macros
\let\part\relax
\let\thepart\relax
% make \part a synonym for \section
\let\part\section
\makeatletter
%% The "@seccntformat" command is an auxiliary command;
%% see pp. 26f. of 'The LaTeX Companion,' 2nd. ed.
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
{\csname the#1\endcsname\quad} % default
{\csname #1@cntformat\endcsname}% enable indiv. control
}
\newcommand{\section@cntformat}{Part \thesection\quad} % affix "Part" to section number's display
\makeatother
\usepackage{chngcntr}
\renewcommand\thesection{\arabic{section}} % do not affix chapter number to sections
\counterwithout{subsection}{section}
\counterwithin{subsection}{chapter} % reset subsection numbers to chapter level
% raise value of 'secnumdepth' and 'tocdepth' counters by 1
\addtocounter{secnumdepth}{1}
\addtocounter{tocdepth}{1}
\usepackage{tocloft} % change some parts of the ToC
\renewcommand\cftchappresnum{Chapter }
\renewcommand\cftsecpresnum{Part } % insert string "Part " before part number
\cftsetindents{chap}{0em}{6em} % control of indentation
\cftsetindents{sec}{2.25em}{3.75em}
\cftsetindents{subsec}{6em}{2em}
\cftsetindents{subsubsec}{8em}{2.75em}
\begin{document}
\tableofcontents
\chapter{First things first}
\part{Etude}
\subsection{Introduction}
\subsection{Other title}
\section{Something} % can use either \part or \section command!
\subsection{A title}
\subsubsection{A subordinated title}
\subsection{Another title}
\subsubsection{Still another subordinated title}
\chapter{Next things sometime later}
\end{document}