ich möchte die Bezeichnung der Querverweise mit \autoref ändern, wenn auf ein Kapitel des Anhangs verwiesen wird. Ich habe schon diese Anweisungen gefunden:
\addto\extrasngerman{%
\renewcommand{\sectionautorefname}{Kapitel}%
\let\subsectionautorefname\sectionautorefname%
\let\subsubsectionautorefname\sectionautorefname%
\let\subsubsubsectionautorefname\sectionautorefname%
}
Das Problem, vor dem ich jetzt stehe, ist, dass ich Kapitel
vor dem Anhang mit "Kapitel"
in dem Anhang mit "Anhang"
nach dem Anhang wieder mit "Kapitel"
referenzieren soll.
Ich habe ein kleines Beispiel gemacht, das die Problematik, denke ich, gut verdeutlicht und hoffe ihr könnt mir helfen:
\documentclass[12pt]{scrartcl}
\usepackage[ngerman]{babel} % Silbentrennung
\usepackage[utf8]{inputenc} % Utf8-Kodierung für Umlaute usw
\usepackage[T1]{fontenc} % Ligaturen, richtige Umlaute im PDF
\usepackage{blindtext}
\usepackage{hyperref}
% 4. Ebene der Überschriften
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}
\setkomafont{sectionentrypagenumber}{\rmfamily\normalfont}
\RedeclareSectionCommands[
level=5,
toclevel=5,
increaselevel=1
]{paragraph,subparagraph}
\DeclareNewSectionCommand[
style=section,
level=4,
counterwithin=subsubsection,
indent=0pt,
beforeskip=-3.25ex plus -1ex minus -0.2ex,
afterskip=1.5ex plus .2ex,
font=\normalfont\bfseries\large,
toclevel=4,
tocindent=7em,
tocnumwidth=4.1em
]{subsubsubsection}
% Anhangsverzeichnis (nach https://komascript.de/comment/5578#comment-5578)
\makeatletter
\DeclareNewTOC[owner=\jobname,listname={Anhang},name={Anhang}]{atoc}
\AfterTOCHead[atoc]{\let\if@dynlist\if@tocleft}
\newcommand*{\useappendixtoc}{%
\renewcommand*{\ext@toc}{atoc}%
\scr@ifundefinedorrelax{hypersetup}{}{%
\hypersetup{bookmarkstype=atoc}%
}%
}
\setuptoc{atoc}{totoc}
\newcommand*{\usestandardtoc}{%
\renewcommand*{\ext@toc}{toc}%
\scr@ifundefinedorrelax{hypersetup}{}{%
\hypersetup{bookmarkstype=toc}%
}%
}
\makeatother
\usepackage{xpatch}
\xapptocmd\appendix{%
\listofatocs%
\useappendixtoc%
% Katitelnummerierungen ändern
\renewcommand*{\thesubsection}{\Alph{section}.\Roman{subsection}}%
\renewcommand*{\thesubsubsection}{\Alph{section}.\Roman{subsection}.\alph{subsubsection}}%
\renewcommand*{\thesubsubsubsection}{\Alph{section}.\Roman{subsection}.\alph{subsubsection}.\roman{subsubsubsection}}%
\newpage%
}{}{}
\newcommand{\postappendix}{%
\usestandardtoc%
% Katitelnummerierungen ändern
\renewcommand{\thesection}{\arabic{section}}%
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}%
\renewcommand{\thesubsubsection}{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}}%
\renewcommand{\thesubsubsubsection}{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}.\arabic{subsubsubsection}}%
}
% Autorefbezeichnung ändern
\addto\extrasngerman{%
\renewcommand{\sectionautorefname}{Kapitel}%
\let\subsectionautorefname\sectionautorefname%
\let\subsubsectionautorefname\sectionautorefname%
\let\subsubsubsectionautorefname\sectionautorefname%
}
\newcommand{\reftab}{%
\begin{tabular}{|p{0.3\linewidth}|p{0.3\linewidth}|p{0.3\linewidth}|}
\hline
\textbf{Ebene} & \textbf{erwartet} & \textbf{tatsächlich} \\ \hline
section & Kapitel 1 & \autoref{sec:Kapitel 1} \\ \hline
subsection & Kapitel 1.1 & \autoref{sec:Kapitel 1.1} \\ \hline
subsubsection & Kapitel 1.1.1 & \autoref{sec:Kapitel 1.1.1} \\ \hline
subsubsubsection & Kapitel 1.1.1.1 & \autoref{sec:Kapitel 1.1.1.1} \\ \hline
section & Anhang A & \autoref{sec:Anhang A} \\ \hline
subsection & Anhang A.I & \autoref{sec:Anhang A.I} \\ \hline
subsubection & Anhang A.I.a & \autoref{sec:Anhang A.I.a} \\ \hline
subsubsubection & Anhang A.I.a.i & \autoref{sec:Anhang A.I.a.i} \\ \hline
section & Kapitel 2 & \autoref{sec:Kapitel 2} \\ \hline
subsection & Kapitel 2.1 & \autoref{sec:Kapitel 2.1} \\ \hline
subsubsection & Kapitel 2.1.1 & \autoref{sec:Kapitel 2.1.1} \\ \hline
subsubsubsection & Kapitel 2.1.1.1 & \autoref{sec:Kapitel 2.1.1.1} \\ \hline
\end{tabular}
}
\begin{document}
\tableofcontents
\newpage
\section{Kapitel 1}\label{sec:Kapitel 1}
\reftab
\subsection{Kapitel 1.1}\label{sec:Kapitel 1.1}
\reftab
\subsubsection{Kapitel 1.1.1}\label{sec:Kapitel 1.1.1}
\reftab
\subsubsubsection{Kapitel 1.1.1.1}\label{sec:Kapitel 1.1.1.1}
\reftab
\newpage
\appendix
\section{Anhang A}\label{sec:Anhang A}
\reftab
\subsection{Anhang A.I}\label{sec:Anhang A.I}
\reftab
\subsubsection{Anhang A.I.a}\label{sec:Anhang A.I.a}
\reftab
\subsubsubsection{Anhang A.I.a.i}\label{sec:Anhang A.I.a.i}
\reftab
\newpage
\postappendix
\section{Post-Anhang 2}\label{sec:Kapitel 2}
\reftab
\subsection{Post-Anhang 2.1}\label{sec:Kapitel 2.1}
\reftab
\subsubsection{Post-Anhang 2.1.1}\label{sec:Kapitel 2.1.1}
\reftab
\subsubsubsection{Post-Anhang 2.1.1.1}\label{sec:Kapitel 2.1.1.1}
\reftab
\end{document}
\usepackage{xpatch}
\xapptocmd\appendix{%
\listofatocs%
\useappendixtoc%
% Katitelnummerierungen ändern
\renewcommand*{\thesubsection}{\Alph{section}.\Roman{subsection}}%
\renewcommand*{\thesubsubsection}{\Alph{section}.\Roman{subsection}.\alph{subsubsection}}%
\renewcommand*{\thesubsubsubsection}{\Alph{section}.\Roman{subsection}.\alph{subsubsection}.\roman{subsubsubsection}}%
\newpage%
% Autorefbezeichnung ändern
\addto\extrasngerman{%
\renewcommand{\sectionautorefname}{Anhang}%
\let\subsectionautorefname\sectionautorefname%
\let\subsubsectionautorefname\sectionautorefname%
\let\subsubsubsectionautorefname\sectionautorefname%
}
}{}{}
