我想用基于文本的枚举替换分段命令的阿拉伯语枚举。例如,在以下文档中:
\documentclass{scrreprt}
\begin{document}
\chapter{Kingdom}\label{king:a}
This is chapter \ref{king:a}
\section{Phylum} \label{phyl:a}
This is section \ref{phyl:a}.
\subsection{Class}\label{class:a}
This is subsection \ref{class:a}
\chapter*{Kingdom}
This is chapter \textit{Kingdom}.
\section*{Kingdom.Phylum}
This is section \textit{Kingdom.Phylum}.
\subsection*{Kingdom.Phylum.Class}
This is subsection \textit{Kingdom.Phylum.Class}.
\end{document}
第一章用一系列以句点分隔的阿拉伯数字来枚举。第二章用以句点分隔的文本来枚举。如何设置文档以自动按章节标题而不是阿拉伯数字进行枚举?
笔记
答案1
既然你提到使用KOMA 文档类对于可接受的答案来说不是必需的,我只是使用了book
类。我认为你想要类似以下内容的东西:
\documentclass{book}
% For referencing current chapter, section etc.
\usepackage{nameref}
\makeatletter
\newcommand*{\currentname}{\@currentlabelname}
\makeatother
\renewcommand{\numberline}[1]{#1~}
% Using egreg's answer
\usepackage{etoolbox}
% Patch the sectioning commands to provide a hook to be used later
\preto{\chapter}{\def\leveltitle{\chaptertitle}}
\preto{\section}{\def\leveltitle{\sectiontitle}}
\preto{\subsection}{\def\leveltitle{\subsectiontitle}}
\preto{\subsubsection}{\def\leveltitle{\subsubsectiontitle}}
\makeatletter
% \@sect is called with normal sectioning commands
% Argument #8 to \@sect is the title
% Thus \section{Title} will do \gdef\sectiontitle{Title}
\pretocmd{\@sect}
{\expandafter\gdef\leveltitle{#8}}
{}{}
% \@ssect is called with *-sectioning commands
% Argument #5 to \@ssect is the title
\pretocmd{\@ssect}
{\expandafter\gdef\leveltitle{#5}}
{}{}
% \@chapter is called by \chapter (without *)
% Argument #2 to \@chapter is the title
\pretocmd{\@chapter}
{\expandafter\gdef\leveltitle{#2}}
{}{}
% \@schapter is called with \chapter*
% Argument #1 to \@schapter is the title
\pretocmd{\@schapter}
{\expandafter\gdef\leveltitle{#1}}
{}{}
\makeatother
\makeatletter
\patchcmd{\@makechapterhead}{\@chapapp\space \thechapter}{Kingdom:}{}{}
\makeatother
\begin{document}
\tableofcontents
\renewcommand{\thechapter}{Kingdom}
\renewcommand{\thesection}{\chaptertitle.Phylum}
\renewcommand{\thesubsection}{\chaptertitle.\sectiontitle.Class}
\chapter{Animalia}
This is chapter \emph{\thechapter\ \currentname}
\section{Arthropoda}
This is section \emph{\thesection\ \currentname}
\subsection{Insecta}
This is subsection \emph{\thesubsection\ \currentname}
\renewcommand{\thechapter}{Kingdom}
\renewcommand{\thesection}{\chaptertitle.Order}
\renewcommand{\thesubsection}{\chaptertitle.\sectiontitle.Family}
\chapter{Plantae}
This is chapter \emph{\thechapter\ \currentname}
\section{Rosales}
This is section \emph{\thesection\ \currentname}
\subsection{Rosacea}
This is subsection \emph{\thesubsection\ \currentname}
\end{document}
您提到文本枚举目录是可选的。以防万一您需要它。我不得不\renewcommand{\numberline}[1]{#1~}
在目录的编号和标题之间使用自然缩进和间距,否则标题会与编号重叠,因为编号已经太宽了。
大部分修改都与如何枚举它们有关。所以我所做的就是使用 egreg 的答案如何获取当前章节名称、节名称、小节名称等?用于传递与其枚举相关的命令的当前章节、部分等。