我尝试创建一个自定义命令\specialchapter
,其工作方式与普通\chapter
命令非常相似,但使用自己的计数器。我希望此 ´\specialchapter` 下的章节编号能够
\chapter{Normal Chapter}
\section{Section}
\subsection{Subsection}
\specialchapter{Special Chapter}
\section{Section}
\subsection{Subsection}
\chapter{Normal Chapter}
\section{Section}
\subsection{Subsection}
应导致章节编号如下:
Chapter 1: Normal Chapter
1.1 Section
1.1.1 Subsection
Special 1: Special Chapter
S1.1 Section
S1.1.1 Subsection
Chapter 2: Normal Chapter
2.1 Section
2.1.1 Subsection
这样做的目的是使其\specialchapter
与那些章节处于同一级别,\chapter
但用前缀字母突出显示这些章节中的部分,以使部分编号明确无误。
我使用 KOMA-Script 并尝试过
\DeclareNewSectionCommand[%
level=0,
style=chapter,
tocstyle=chapter,
tocindent=0pt,
toclevel=0,
tocnumwidth=1.5em,
beforeskip=0pt,
]{specialchapter}
\def\thespecialchapter{S\arabic{specialchapter}}%
这将创建类似章节的命令,但此命令下的章节将从最后一个命令继续编号\chapter
。
答案1
specialchapter
必须使用与章节相同的重置列表:
\makeatletter
\let\cl@specialchapter\cl@chapter% use the same reset list
\makeatother
当新的特殊章节开始时,这将重置章节编号。但\thesection
仍定义为\thechapter.\arabic{section}
。这可以通过以下方式更改
\newcommand*\originalthechapter{}
\let\originalthechapter\thechapter
\AddtoDoHook{heading/preinit/specialchapter}{\useinnumbers{\thespecialchapter}}
\AddtoDoHook{heading/preinit/chapter}{\useinnumbers{\originalthechapter}}
\newcommand*\useinnumbers[2]{\gdef\thechapter{#1}}
它也适用于图形、表格等。
例子:
\documentclass{scrreprt}
\DeclareNewSectionCommand[%
level=\chapternumdepth,
style=chapter,
tocstyle=chapter,
tocindent=0pt,
toclevel=\chaptertocdepth,
tocnumwidth=1.5em,
beforeskip=0pt,
]{specialchapter}
\renewcommand\thespecialchapter{S\arabic{specialchapter}}%
\makeatletter
\let\cl@specialchapter\cl@chapter% use the same reset list
\makeatother
\newcommand*\originalthechapter{}
\let\originalthechapter\thechapter
\AddtoDoHook{heading/preinit/specialchapter}{\useinnumbers{\thespecialchapter}}
\AddtoDoHook{heading/preinit/chapter}{\useinnumbers{\originalthechapter}}
\newcommand*\useinnumbers[2]{\gdef\thechapter{#1}}
\begin{document}
\tableofcontents
\listoffigures
\chapter{Normal Chapter}
\section{Section}
\subsection{Subsection}
\captionof{figure}{A figure in Normal Chapter}
\chapter{Normal Chapter}
\section{Section}
\subsection{Subsection}
\captionof{figure}{A figure in Normal Chapter}
\specialchapter{Special Chapter}
\section{Section}
\subsection{Subsection}
\captionof{figure}{A figure in Special Chapter}
\chapter{Normal Chapter}
\section{Section}
\subsection{Subsection}
\captionof{figure}{A figure in Normal Chapter}
\end{document}