0

I am trying to create the following simple document structure (but with more than just two parts) with scrartcl:

Document structure

I use \counterwithin*{section}{part} to number sections within parts. For the appendices, I expected the appendix package to be the solution:

\documentclass{scrartcl}

\usepackage{appendix} \usepackage{chngcntr} \usepackage{hyperref}

\counterwithin*{section}{part}

\begin{document}

\part{First Part} \section{First Section} \label{sec:first-first} \section{Second Section}

\begin{appendices} \section{First Appendix} \label{sec:app-first-first} \section{Second Appendix} \end{appendices}

\part{Second Part} \section{First Section} \label{sec:second-first} \section{Second Section} \begin{appendices} \section{First Appendix} \label{sec:app-second-first} \section{Second Appendix} \end{appendices}

\end{document}

The Problem: This seems to ignore the \counterwithin. The first appendix in Part II (sec:app-second-first) is numbered "C", not "A" as expected.

What I've tried:

  1. Explicitly adding \AtBeginEnvironment{appendices}{\counterwithin*{section}{part}} has no effect.
  2. I also tried to avoid the appendix package and just add \setcounter{section}{0} \renewcommand{\thesection}{\Alph{section}} before and \renewcommand{\thesection}{\arabic{section}} after each appendix, but this confuses hyperref: sec:app-first-first and sec:app-second-first will both jump to sec:first-first.
  3. [update] I figured out that the workaround from (2) combined with hypertexnames=false works (full MWE), but as using the appendices environment seems to be the "cleaner" and recommended solution, I'd still like to know how to tweak the numbering within appendices.

Question: How can I reset the section counter in each appendices environment (without breaking hyperref)?

CL.
  • 901

2 Answers2

1

The appendix package adds a couple of new counters: @ppsaveapp and @ppsavesec. I tried \counterwithin on both of them, but only @ppsaveapp made a difference.

\documentclass{scrartcl}

\usepackage{appendix} \usepackage{chngcntr} \usepackage{hyperref}

\counterwithin{section}{part} \counterwithin{@ppsaveapp}{part}

\begin{document}

\part{First Part} \section{First Section} \label{sec:first-first} \section{Second Section}

\begin{appendices} \section{First Appendix} \label{sec:app-first-first} \section{Second Appendix} \end{appendices}

\part{Second Part} \section{First Section} \label{sec:second-first} \section{Second Section} \begin{appendices} \section{First Appendix} \label{sec:app-second-first} \section{Second Appendix} \end{appendices}

\end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
0

Adding \appendix instead of \begin{appendices}...\end{appendices} may solve your problem.

Full working example:

\documentclass{scrartcl}

\usepackage{appendix} \usepackage{chngcntr} \usepackage{hyperref}

\counterwithin*{section}{part}

\begin{document}

\part{First Part} \section{First Section} \label{sec:first-first} \section{Second Section}

\begin{appendices} \section{First Appendix} \label{sec:app-first-first} \section{Second Appendix} \end{appendices}

\part{Second Part} \section{First Section} \label{sec:second-first} \section{Second Section} \appendix \section{First Appendix} \label{sec:app-second-first} \section{Second Appendix}

\end{document}

mmr
  • 2,249
  • 5
  • 22
  • Thanks for this suggestion! However, this only solves the special case of exactly 2 parts (which, admittedly, I presented in the question) but cannot address the general case with >2 parts. – CL. Nov 22 '21 at 11:23