3

I want to use sub-numbering for certain theorems. I used the solution provided in the question How do I get sub-numbering for theorems (Theorem 1.A., Theorem 1.B., Theorem 2.)?, which does exactly what I want.

However, there seems to be an issue with hyperref. Upon compilation I get a warning

destination with the same identifier (name{theorem1.1}) has already been used, duplicate ignored < to be read again > relaxl.197 (...)

The output pdf document is fine, except that when using a \ref to a "subtheorem", clicking on the output hyperlink sends to the wrong theorem (in my case it links to Proposition 1.2 instead of Theorem 19.B).

I would be grateful if anyone knows how to fix this or suggest an alternative.

2
  • Can you please add a full minimal working example so that people can see what packages etc you need to get your code to work (but don't add code that is not needed). This makes it much easier for people to help you. – user30471 Feb 28 '15 at 3:55
  • @Andrew: I was about to add a full minimal working example as you rightly requested, but then there was already a posted answer which solves my problem perfectly. – Seub Feb 28 '15 at 5:01
2

You need to also adjust the H-style counter associated with thm:

enter image description here

\documentclass{article}

\usepackage{hyperref}
\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}}%
  % To keep hyperref happy, update H-counter as well
  \expandafter\def\csname theH#1\endcsname{thm.\theparentnumber.\Alph{#1}}%
  \unskip\ignorespaces
}{%
  \setcounter{\subtheoremcounter}{\value{parentnumber}}%
  \ignorespacesafterend
}
\makeatother
\newcounter{parentnumber}

\newtheorem{thm}{Theorem}

\begin{document}

\begin{thm}\label{thm:one}
One
\end{thm}

\begin{subtheorem}{thm}\label{thm:two}%
\begin{thm}\label{thm:twoA}
Two, first part
\end{thm}

\begin{thm}\label{thm:twoB}
Two, second part
\end{thm}
\end{subtheorem}

\begin{thm}\label{thm:three}
Three
\end{thm}

\ref{thm:one}, \ref{thm:two}, \ref{thm:twoA}, \ref{thm:twoB}, \ref{thm:three}.

\end{document}

Note the addition of \unskip as well, to avoid spurious vertical spacing at the start of the subtheorem environment.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.