1

I have to deal with appendices in multiple papers which are represented by chapters. For this purpose I had to rewrite the appendix-environment (see MWE). It now is at the section layer.

The different appendices are in the subsections of the appendix environment. I also want to use hyperref to enable direct links to the appendices in the PDF. However, with my current solution the hyperlink does not refer to the correct appendix but to the subsections of the third section in paper 1.

How can I achieve an appendix-environment in chapters with functioning hyperrefs to the appendices. How do I have to change the rewrite-command?

\documentclass[a4paper, 12pt]{scrbook}

\usepackage{blindtext}
\usepackage[hidelinks,colorlinks=false,linkcolor=black,urlcolor=black,breaklinks=true]{hyperref}

\renewenvironment{appendix}{%
  \clearpage
  \section*{Appendices}%
  \addcontentsline{toc}{section}{Appendices}
  \renewcommand{\thesubsection}{\alph{subsection}}
  \setcounter{subsection}{0}
}{}

\begin{document}

\chapter{Paper 1}

\section{the first section}
\blindtext

\section{the second section}
\label{sec:two}
This can be found in appendix \ref{app:theapp}

\section{the third section}
\label{sec:third}

\subsection{the subsection of third}

\blindtext

\subsection{the second subsection of third}

\blindtext

\newpage
\begin{appendix}

\subsection{The Appendix 1}
\label{app:theapp}

\subsection{The Appendix 2}
\label{app:theapp2}

\end{appendix}

\chapter{Paper 2}

\blindtext

\chapter{Paper 3}

\blindtext

\newpage




\end{document}
2
  • hyperref does warn you: [2]pdfTeX warning (ext4): destination with the same identifier (name{subsection .1.3.1}) has been already used, duplicate ignored <to be read again> Sep 3, 2019 at 20:20
  • I suggest that you start reading the KOMA-script manual and use the internal commands to redefine the appendix. Then KOMA-script will ensure that you do not run into all types of incompatibilities. For example: It is explicitly stated that \appendix is a command, not an environment. You should have used \RedeclareSectionCommand[attributes ]{name } see manual page 459. Also, you should have use options to the documentclass to set appendix in one line, etc.
    – Sveinung
    Sep 3, 2019 at 20:41

1 Answer 1

4

hyperref does warn you:

 pdfTeX warning (ext4): destination with the same identifier (name{subsection
.1.3.1}) has been already used, duplicate ignored

You need to make sure the H... version of the counter used for generating internal references is unique, hyperref needs a bit of help here as you use an unnumbered section as the parent section level.

\documentclass[a4paper, 12pt]{scrbook}

\usepackage{blindtext}
\usepackage[hidelinks,colorlinks=false,linkcolor=black,urlcolor=black,breaklinks=true]{hyperref}

\renewenvironment{appendix}{%
  \clearpage
  \section*{Appendices}%
  \addcontentsline{toc}{section}{Appendices}
  \renewcommand{\theHsubsection}{A.\alph{subsection}}
  \renewcommand{\thesubsection}{\alph{subsection}}
  \setcounter{subsection}{0}
}{}

\begin{document}

\chapter{Paper 1}

\section{the first section}
\blindtext

\section{the second section}
\label{sec:two}
This can be found in appendix \ref{app:theapp}

\section{the third section}
\label{sec:third}

\subsection{the subsection of third}

\blindtext

\subsection{the second subsection of third}

\blindtext

\newpage
\begin{appendix}

\subsection{The Appendix 1}
\label{app:theapp}

\subsection{The Appendix 2}
\label{app:theapp2}

\end{appendix}

\chapter{Paper 2}

\blindtext

\chapter{Paper 3}

\blindtext

\newpage




\end{document}

You must log in to answer this question.

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