I have included sub-numbered theorems according to the suggestion for this question: How do I get sub-numbering for theorems (Theorem 1.A., Theorem 1.B., Theorem 2.)?
This works great, and it visually incorporates fine with the \cref{}
command of the cleveref
package. However, it somehow messes up the target for the hyperlinks that are generated. Specifically, I generated Theorems 2.A
and 2.B
, but any link to 2.A
jumps to Theorem 1
.
\documentclass{article}
\usepackage[colorlinks=true]{hyperref}
\usepackage{cleveref}
\newtheorem{thm}{Theorem}
\crefname{thm}{Theorem}{Theorems}
\makeatletter \newenvironment{subtheorem}[1]{%
\def\subtheoremcounter{#1}%
\refstepcounter{#1}%
\protected@edef\theparentnumber{\csname the#1\endcsname}%
\setcounter{parentnumber}{\value{#1}}%
\setcounter{#1}{0}%
\expandafter\def\csname the#1\endcsname{\theparentnumber.\Alph{#1}}%
\ignorespaces
}{%
\setcounter{\subtheoremcounter}{\value{parentnumber}}%
\ignorespacesafterend
}
\makeatother
\newcounter{parentnumber}
\begin{document}
\begin{thm}\label{thm1}
...
\end{thm}
\begin{subtheorem}{thm}
\begin{thm}
Part A\label{thm3a}
\end{thm}
\begin{thm}
Part B
\end{thm}
\end{subtheorem}
This link is correctly labeled as \cref{thm3a} but actually jumps back to \cref{thm1}.
\end{document}
Any idea how to fix that?
cleveref
as the last package?\setcounter{#1}{0}
command -- this leads to non-unique counter settings and thereby to wrong anchors