1

I use subparagraphs with KOMA-script to create a custom section environment. Its label is determined by the counter of the according subsection and the subparagraph counter.

Now I would to offset the display of the subsection counter in the label of the subparagraph by e.g. 3, but I do not want to change the subsection counter itself in this process. So I see two options:

  • create a new counter, link it to the subsection counter, but with an offset of 3. It should increment parallel to the subsection. I'd like to avoid to do that manually
  • include the offset within \arabic{}, which I use to create the label of the subparagraph.

But I cannot get to work any of the approaches. Do you have any ideas?

MWE

\documentclass{scrreprt}

\usepackage{calc}

\def\apoffset{3}  % offset
\setcounter{secnumdepth}{6} 

\makeatletter  % subparagraph definition
\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\z@}%
  {0.3\baselineskip \@plus1ex \@minus .2ex}%
  {0.75ex plus 0.1ex}% space after heading
  {\normalfont\mdseries\itshape}}
\makeatother 

% new counter approach?
%\newcounter{ap}
%\setcounter{ap}{\value{subsection}+\apoffset}

\renewcommand{\thesubparagraph}{\noindent AP \arabic{subsection}-\arabic{subparagraph}}
%\renewcommand{\thesubparagraph}{\noindent AP \arabic{ap}-\arabic{subparagraph}}  % <- does not increment

\begin{document}

\chapter{Chapter}
\section{Section}
\subsection{Subsection 1}
\subparagraph{Subparagraph 4.1}
\subparagraph{Subparagraph 4.2}

\subsection{Subsection 2}
\subparagraph{Subparagraph 5.1}
\subparagraph{Subparagraph 5.2}

\end{document}

3 Answers 3

1

While you use a KOMA-Script class, do not redefine \subparagraph. You can change the settings for subparagraph using \RedeclareSectionCommand:

\RedeclareSectionCommand[
  indent=0pt,
  beforeskip=.3\baselineskip plus 1ex minus .2ex,
  afterskip=.75ex plus .1ex,
  afterindent=true,
  runin=false,
  font=\normalfont\mdseries\itshape
]{subparagraph}

You could define a new counter ap, set the counter to the offset value for each new section und step the counter for each numbered subsection:

\newcounter{ap}
\renewcommand*{\thesubparagraph}{\noindent AP \arabic{ap}-\arabic{subparagraph}}

% reset the ap counter to \resetap when a new section starts:
\AddtoDoHook{heading/begingroup/section}{\resetap}
\newcommand*{\resetap}[1]{\setcounter{ap}{\apoffset}}

% step the ap counter when a numbered subsection starts:
\AddtoDoHook{heading/begingroup/subsection}{\stepap}
\newcommand*{\stepap}[1]{\IfUseNumber{\stepcounter{ap}}{}}% can be used only between .../begingroup/... and .../endgroup/... hooks

enter image description here

\documentclass{scrreprt}

\newcommand*\apoffset{3}  % offset
\setcounter{secnumdepth}{\subparagraphnumdepth} 

\RedeclareSectionCommand[
  indent=0pt,
  beforeskip=.3\baselineskip plus 1ex minus .2ex,
  afterskip=.75ex plus .1ex,
  afterindent=true,
  runin=false,
  font=\normalfont\mdseries\itshape
]{subparagraph}

\newcounter{ap}
\renewcommand*{\thesubparagraph}{\noindent AP \arabic{ap}-\arabic{subparagraph}}

% reset the ap counter to \resetap when a new section starts:
\AddtoDoHook{heading/begingroup/section}{\resetap}
\newcommand*{\resetap}[1]{\setcounter{ap}{\apoffset}}

% step the ap counter when a numbered subsection starts:
\AddtoDoHook{heading/begingroup/subsection}{\stepap}
\newcommand*{\stepap}[1]{\IfUseNumber{\stepcounter{ap}}{}}% can be used only between .../begingroup/... and .../endgroup/... hooks

\begin{document}
\chapter{Chapter}
\section{Section}
\subsection*{Unnumbered subsection}
\subsection{Subsection 1}
\subparagraph{Subparagraph 4.1}
\subparagraph{Subparagraph 4.2}

\subsection{Subsection 2}
\subparagraph{Subparagraph 5.1}
\subparagraph{Subparagraph 5.2}

\section{Section}
\subsection{Subsection 1}
\subparagraph{Subparagraph 4.1}
\subparagraph{Subparagraph 4.2}

\subsection*{Another unnumbered subsection}

\subsection{Subsection 2}
\subparagraph{Subparagraph 5.1}
\subparagraph{Subparagraph 5.2}
\end{document}
1
  • This seems to be the most elegant koma-script solution.. Apr 22, 2021 at 18:23
1

I'm a bit unclear on what you're trying to do, but I think I have the general idea. Aside from abusing \subparagraph what you want to do is make sure that you set the counter value of ap at the right time. What you have now sets it once to \value{subsection}+\apoffset (well, not really, because you can't put expressions like that in the argument to \setcounter) and never changes it again.

So lets try doing this right. Rather than abuse \subparagraph let's make a new command \apsection which has depth 3. We can use \@startsection to set the title as you've done, but we'll change a couple values:

\makeatletter  % subparagraph definition
\newcommand{\apsection}{\@startsection{ap}{3}{\z@}%
  {0.3\baselineskip \@plus1ex \@minus .2ex}%
  {0.75ex plus 0.1ex}% space after heading
  {\normalfont\mdseries\itshape}}
\makeatother 

Now comes the tricky bit. How and where do we set the value to be printed as part of the number here. It looks like what you want to do is print (subsection + \apoffset) a dash and then the ap value which will be numbered inside subsections. When we define ap we'll need to make sure it resets with subsections by writing

\newcounter{ap}[subsection]

and to print the correct value, we'll need to have an extra counter that we'll manipulate as necessary. Let's call that counter apPrefix:

\newcounter{apPrefix}

Then we'll modify our definition of \apsection to set the value of apPrefix before we call \@startsection:

\newcommand{\apsection}{%
  \setcounter{apPrefix}{\value{section}}%
  \addtocounter{apPrefix}{\apoffset}%
  \@startsection{ap}{3}{\z@}%
    {0.3\baselineskip \@plus1ex \@minus .2ex}%
    {0.75ex plus 0.1ex}% space after heading
    {\normalfont\mdseries\itshape}}

Doing it this way makes sure that if you were to use \label and \ref with your \ap command, you get the correct value in the reference.

Finally, we'll define \theap to print the value:

\renewcommand{\theap}{AP \arabic{apPrefix}-\arabic{ap}}

I'm not sure what you're trying to accomplish with the \noindent but I can guarantee that putting it inside the definition of \theCOUNTER is the wrong approach.

1

You can use a lower level interface for producing numbers and pass the value you want.

\documentclass{scrreprt}

\newcommand\apoffset{3}  % offsec
\setcounter{secnumdepth}{6} 

\makeatletter  % subparagraph definition
\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\z@}%
  {0.3\baselineskip \@plus1ex \@minus .2ex}%
  {0.75ex plus 0.1ex}% space after heading
  {\normalfont\mdseries\itshape}}
\renewcommand{\thesubparagraph}{%
  AP\@arabic{\numexpr\value{subsection}+\apoffset\relax}-\arabic{subparagraph}%
}
\makeatother 

\begin{document}

\chapter{Chapter}
\section{Section}
\subsection{Subsection 1}
\subparagraph{Subparagraph 4.1}
\subparagraph{Subparagraph 4.2}

\subsection{Subsection 2}
\subparagraph{Subparagraph 5.1}
\subparagraph{Subparagraph 5.2}

\end{document}

enter image description here

I removed \noindent that doesn't belong there.

You must log in to answer this question.

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