0

I would like to replace the Arabic enumeration of the sectioning commands with text-based enumeration. For example, in the following document:

\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}

Arabic vs text enumeration

The first chapter is enumerated with a series of Arabic numerals separated by periods. The second chapter is enumerated by text separated by periods. How can I setup a document to automatically enumerate by a section's header instead of Arabic numerals?

Notes

  • The above example uses the KOMA document class scrreprt. A valid answer would not be required to use this document class.
  • This answer comes close to the desired behavior, but has the disadvantage of the enumerating text is fixed at the redefinition of the section command and not dynamic.
  • I am not asking about the enumerate or itemize environments (at least, 75% sure I'm not).
4
  • 2
    I assume you don't want such section styling in TOC?
    – SolidMark
    Jul 6, 2021 at 20:22
  • 1
    Actually, a text-enumerated TOC would be preferable, but not required for an accepted answer.
    – cms
    Jul 6, 2021 at 20:27
  • IMHO such style can make navigations so very painful… (Are you sure you want to do this to your potential readers?) Jul 7, 2021 at 1:50
  • @RuixiZhang I think that depends on if the information is arranged into categories (eg a reference manual) or is sequential (eg a textbook).
    – cms
    Aug 17, 2021 at 3:38

1 Answer 1

1

Since you mentioned that using a KOMA document class is not necessary for an acceptable answer, I simply used book class. I think you want something like the following:

\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}

Animalia Plantae

And you mentioned that text-enumerated TOC is optional. Just in case you want it. I had to use \renewcommand{\numberline}[1]{#1~} for natural indention and spacing between the numbering and the title for the TOC, without which the title overlaps with the numbering since the numbering is already too wide.

TOC

Much of the modification has to do with how they are to be enumerated. So what I did is use egreg's answer from How to get the current chapter* name, section* name, subsection* name, etc? for passing the current chapter, section etc. for the commands concerned with their enumeration.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .