I'm currently creating a big document with multiple TeX-files
and used dozens of links to parts I put into theorem-environments.
However, some of the links do not work, they just take me to the first
page of the document.
It seems like using an 'enumerate-environment'
at the beginning of the content of the
thm-environment will cause the link associated to that thm-environment
to take me to the first page (maybe I was not able to use
'\label' correctly in this case).
Here is the code, after deleting most of the content and clearing the header:
\documentclass[12pt, a4paper]{article}
% font, language
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
%maths
\usepackage{mathrsfs}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
%general formatting
\usepackage{enumitem}
%environments
\theoremstyle{definition}
\newtheorem{rem}[thm]{Bemerkung}
%hyperref
\usepackage[
colorlinks=true,
urlcolor=purple,
linkcolor=purple!87!black,
pdfborder={0 0 0}
]{hyperref}
\begin{document}
\section{This is where the link takes me to}
\subsection{instead of remark 1.2}
\newpage
\begin{rem}\label{broken_ref}
\begin{enumerate}[label=\roman*)]
\item
relevant content.
\item
relevant content 2.
\end{enumerate}
\end{rem}
\begin{rem}\label{working_ref}
If I do not begin the content of the remark with an 'enumerate-environment',
it works...
\begin{enumerate}[label=\arabic*)]
\item
relevant content
\end{enumerate}
\end{rem}
\pagebreak
Link that does not work $\to$ \ref{broken_ref} \reflectbox{$\to$}.\\
Link that does work $\to$ \ref{working_ref} \reflectbox{$\to$}.
\end{document}
Can someone explain to me, why it does not work, when I begin the remark with an enumerate environment ?
Best Answer
This is a minimised example. I think that you need to define new theorems etc. after loading
hyperref
so that counters are set up correctly to give destination anchors unique names and so that targets of links work correctly. See section 3.2 of the package manual.