2

I try to create a custom command \specialchapter that works very similar to the normal \chapter command, but uses it's own counter. And I would like for the section numbering under this ´\specialchapter` to

\chapter{Normal Chapter}
\section{Section}
\subsection{Subsection}

\specialchapter{Special Chapter}
\section{Section}
\subsection{Subsection}

\chapter{Normal Chapter}
\section{Section}
\subsection{Subsection}

should result in section numbering like this:

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

The idea is to have \specialchapter on the same level as \chapter but highlight sections in those chapters with a prefix letter to make the section numbering unambiguous.

I use KOMA-Script and tried

\DeclareNewSectionCommand[%
    level=0,
    style=chapter,
    tocstyle=chapter,
    tocindent=0pt,
    toclevel=0,
    tocnumwidth=1.5em,
    beforeskip=0pt,
]{specialchapter}
\def\thespecialchapter{S\arabic{specialchapter}}%

This creates the chapter-like command, but the sections under this command continue their numbering from the last \chapter command.

1 Answer 1

2

specialchapter must use the same reset list as chapter:

\makeatletter
\let\cl@specialchapter\cl@chapter% use the same reset list
\makeatother

This resets the section number, when a new specialchapter starts. But \thesection is still defined as \thechapter.\arabic{section}. This can be changed by

\newcommand*\originalthechapter{}
\let\originalthechapter\thechapter
\AddtoDoHook{heading/preinit/specialchapter}{\useinnumbers{\thespecialchapter}}
\AddtoDoHook{heading/preinit/chapter}{\useinnumbers{\originalthechapter}}
\newcommand*\useinnumbers[2]{\gdef\thechapter{#1}}

which will work for figures, tables etc. too.

Example:

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

enter image description here

You must log in to answer this question.

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