![为什么 \ref 不跳至附录而是跳至第 3 节的小节?](https://linux22.com/image/401230/%E4%B8%BA%E4%BB%80%E4%B9%88%20%5Cref%20%E4%B8%8D%E8%B7%B3%E8%87%B3%E9%99%84%E5%BD%95%E8%80%8C%E6%98%AF%E8%B7%B3%E8%87%B3%E7%AC%AC%203%20%E8%8A%82%E7%9A%84%E5%B0%8F%E8%8A%82%EF%BC%9F.png)
我必须处理多篇论文中的附录,这些附录以章节为代表。为此,我不得不重写附录环境(参见 MWE)。它现在位于章节层。
不同的附录位于附录环境的子部分中。我还想使用 hyperref 来启用 PDF 中附录的直接链接。但是,使用我目前的解决方案,超链接指向的不是正确的附录,而是论文 1 中第三部分的子部分。
如何在章节中实现附录环境,并让附录的超链接功能正常运作。我该如何更改重写命令?
\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}
答案1
hyperref 会警告你:
pdfTeX warning (ext4): destination with the same identifier (name{subsection
.1.3.1}) has been already used, duplicate ignored
您需要确保H...
用于生成内部引用的计数器的版本是唯一的,由于您使用未编号的部分作为父部分级别,因此 hyperref 在这里需要一些帮助。
\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}