# Enumerate after \label

I have the following code:

\usepackage{hyperref}
\newtheorem{thm}{Theorem}

\begin{thm} \label{mythm}
\begin{enumerate}
\item
\end{enumerate}
\end{thm}

\ref{mythm}


The ref prints the right number. However, when I click on it, it will lead me to a wrong page (basically, to the beginning of the document). pdflatex also has some warning. If I add  between \begin{thm} and \begin{enumerate}, the problem disappears, but now, the enumeration starts a new line. Is there any way to fix this?

-

You can use the \phantomsection command from hyperref:

\documentclass{book}
\usepackage{amsthm}
\usepackage{hyperref}

\newtheorem{thm}{Theorem}

\begin{document}

\begin{thm}\phantomsection \label{mythm}
\begin{enumerate}
\item
\end{enumerate}
\end{thm}

\ref{mythm}

\end{document}


Another option would be to use the ntheorem package instead of amsthm:

\documentclass{book}
\usepackage{ntheorem}
\usepackage{hyperref}

\newtheorem{thm}{Theorem}

\begin{document}
\mbox{}\newpage
\begin{thm}
\label{mythm}
\begin{enumerate}
\item
\end{enumerate}
\end{thm}

\newpage
\ref{mythm}

\end{document}

-
For ntheorem, do I need to also define the proof environment? –  brian Mar 21 '11 at 21:27
@brian: if you load the package with the standard option, then some predefined theorem-like environments become available, proof amongst them (you'll also need the thmmarks package option to activate the endmark). If you don't load those options, you'll have to define your own proof environment. –  Gonzalo Medina Mar 21 '11 at 21:39

MWE:

\documentclass[12pt]{article}

\usepackage{amsthm}

\newtheorem{thm}{Theorem}

\begin{document}

\begin{thm} \label{thm:test}
\begin{enumerate}
\item First thing.
\item Second thing.
\item Third thing.
\end{enumerate}
\end{thm}

Reference to Theorem~\ref{thm:test}.

\end{document}


The theorem environment of amsthm delays the anchor setting to the start of the next paragraph via \everypar. However the first \item of environment enumerate clears it by \everypar{}. Thus the anchor is lost for the \label{thm:test}.

A normal paragraph start would set the anchor. The answer of John Kormylo start the paragraph with \strut, an invisible rule with a height and depth. The following example uses \noindent:

\documentclass[12pt]{article}

\usepackage{amsthm}

\newtheorem{thm}{Theorem}

\begin{document}

\begin{thm}
\noindent\label{thm:test}
\begin{enumerate}
\item First thing.
\item Second thing.
\item Third thing.
\end{enumerate}
\end{thm}

Reference to Theorem~\ref{thm:test}.

\end{document}


Then the first item moves from the theorem title line to the next line, the number aligned with the other numbers of the enumeration. Therefore I would call it a feature.

Otherwise \phantomsection instead of \noindent can be used, as shown in the answer of Gonzalo Medina:

\documentclass[12pt]{article}

\usepackage{amsthm}

\newtheorem{thm}{Theorem}
\def\thmautorefname{Theorem}

\begin{document}

\begin{thm}
\phantomsection\label{thm:test}
\begin{enumerate}
\item First thing.
\item Second thing.
\item Third thing.
\end{enumerate}
\end{thm}

Theorem~\ref{thm:test} and \autoref{thm:test}.

\end{document}


\phantomsection does not start a new paragraph, therefore the original anchor for the theorem label is still lost. But it creates a new anchor, that is then used by the following \label.

However, \phantomsection does not create a theorem anchor, but an anchor with the internal name of a section. Therefore \autoref will refer to the theorem as "section".

As workaround, the correct anchor can be set via \hyper@anchor:

\documentclass[12pt]{article}

\usepackage{amsthm}

\newtheorem{thm}{Theorem}
\def\thmautorefname{Theorem}

\begin{document}

\begin{thm}
\makeatletter
\hyper@anchor{\@currentHref}%
\makeatother
\label{thm:test}
\begin{enumerate}
\item First thing.
\item Second thing.
\item Third thing.
\end{enumerate}
\end{thm}

Theorem~\ref{thm:test} and \autoref{thm:test}.

\end{document}


-
A better command than \phantomsection would be welcome. ;-) What about \makeanchor? –  egreg Jul 24 '14 at 19:50
@egreg: Is not this easy. Also a unique anchor name is needed. I doubt, a normal user would know to use \@currentHref or thm.\theHthm here. –  Heiko Oberdiek Jul 24 '14 at 19:54
@HeikoOberdiek: I don't really understand what you mean. And I know that it's hard to patch packages so that they fit with hyperref, but what about doing so for amsthm? –  Antoine Chambert-Loir Oct 20 '14 at 9:20
@AntoineChambert-Loir I do not know, what are you referring to, but if you want to improve the compatibility of amsthm and hyperref, then you or other volunteers are free to go ahead. –  Heiko Oberdiek Oct 20 '14 at 18:20
@HeikoOberdiek: Inded, I'll try to find out how to arrange that. As a matter of fact, my question was referring to your comment "I doubt, a normal user..." –  Antoine Chambert-Loir Oct 20 '14 at 19:25

Even simpler...

\documentclass{book}
\usepackage{amsthm}
\usepackage{hyperref}

\newtheorem{thm}{Theorem}

\begin{document}

\begin{thm}\label{mythm}\strut% ******************
\begin{enumerate}
\item
\end{enumerate}
\end{thm}

\ref{mythm}

\end{document}

-
I suspect that this clever solution may be more clever and less a solution to the problem at hand. In particular, I suspect that it might break down if and when either amsthm or hyperref are updated at some point in the future. However, this is no more than a suspicion for just now. I'd be happy to be shown wrong. –  Mico Jun 28 '14 at 15:36
@Mico - One would hope than any updates will actually fix the problem in the first place. –  John Kormylo Jun 28 '14 at 15:38
One should always hope... Nothing wrong with hope! :-) –  Mico Jun 28 '14 at 15:40