I'm trying to mix the caption
, hyperref
, and algorithm2e
packages, but I am having some issues. Here is a MWE.
\documentclass[12pt]{book}
\usepackage{float}
\usepackage[footnotesize,bf,center,figurename=Fig]{caption}
\usepackage{amsmath}
\usepackage{xpatch}
\usepackage[vlined,ruled]{algorithm2e}
\xpretocmd{\algorithm}{\hsize=\linewidth}{}{}
\usepackage[colorlinks,citecolor=green!90!black,draft=false,pdfencoding=auto]{hyperref}
\usepackage{cleveref}
\begin{document}
\listoffigures
\newpage
\begin{algorithm}[H]
\DontPrintSemicolon
\renewcommand\figurename{Algorithm}
\captionof{figure}{FOO.\label{alg:foo}}
\KwIn{}
\end{algorithm}
\begin{figure}[H]
~
\caption{Consistent numbering between figures and algorithms.}
\end{figure}
\newpage
\captionsetup{list=no}
\begin{algorithm}[H]
\DontPrintSemicolon
\renewcommand\figurename{Algorithm}
\captionof{figure}{BAR.\label{alg:bar}}
\KwIn{}
\end{algorithm}
\captionsetup{list=yes}
\begin{algorithm}[H]
\DontPrintSemicolon
\renewcommand\figurename{Algorithm}
\captionof{figure}{FOOBAR.\label{alg:foobar}}
\KwIn{}
\end{algorithm}
Ref: \ref{alg:foobar}.
\end{document}
There are two problems:
- algorithm BAR is in the list of figures, while it is not supposed to because of
captionsetup
. - the reference to algorithm FOOBAR links to algorithm FOO, both in the list of figures and in page 3.
Thank you for looking.