I am trying to create the following simple document structure (but with more than just two parts) with scrartcl:
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:
- Explicitly adding
\AtBeginEnvironment{appendices}{\counterwithin*{section}{part}}has no effect. - I also tried to avoid the
appendixpackage and just add\setcounter{section}{0} \renewcommand{\thesection}{\Alph{section}}before and\renewcommand{\thesection}{\arabic{section}}after each appendix, but this confuseshyperref:sec:app-first-firstandsec:app-second-firstwill both jump tosec:first-first. - [update] I figured out that the workaround from (2) combined with hypertexnames=false works (full MWE), but as using the
appendicesenvironment seems to be the "cleaner" and recommended solution, I'd still like to know how to tweak the numbering withinappendices.
Question: How can I reset the section counter in each appendices environment (without breaking hyperref)?

\counterwithin*{@ppsaveapp}{part}. – John Kormylo Nov 22 '21 at 13:32