I am using hyperref to typeset a book containing many different research articles. Each article has its own set of theorems, definitions etc. and with every \maketitle the corresponding counters are reset, just as one would expect. Thus, there are multiple "Theorem 1" etc. This seems to be no problem for hyperref since they all have different anchors; everything is as it should be.
Now some of the articles contain algorithms typeset with algorithm2e and the counters for those are not reset by default, which is why I put a
\setcounter{algocf}{0}
in front of every article. This changes the label, but I get
destination with the same identifier (name {algocf.1})
has been already used, duplicate ignored
and the hyperref link always points to the "first" Algorithm 1 etc.
I am afraid this solution (where figures and tables were considered) does not work for my problem:
hyperref points wrong figure/table with reset counter
I tried
\renewcommand{\theHalgocf}{new.\thealgocf}
but to no avail.
The same problem appears with the subfloat command from the subfig package (here, counters are reset, but anchors are still ambiguous):
destination with the same identifier (name{subfigure.4.2})
has been already used, duplicate ignored
MWE
\documentclass{article}
\usepackage{algorithm2e}
\usepackage{hyperref}
\usepackage{cleveref}
\crefname{algorithm}{Algorithm}{Algorithms}
\begin{document}
\begin{algorithm}
\caption{Algo 1}\label{1}
Test\;
\end{algorithm}
\setcounter{algocf}{0}
\begin{algorithm}
\caption{Algo 2}\label{2}
Test\;
\end{algorithm}
\Cref{1} and \cref{2}.
\end{document}
\documentclass{...}
and ending with\end{document}
.\maketitle
does not reset counters, apart fromfootnote
. By default, you can't use\maketitle
more than once as well (well, you can, but it does nothing after the first usage)