Juanjo wrote:The original documentclass, Thesis.cls, is based on book.cls and loads caption and hyperref in the order given in the following code:
Loading hyperref in a document class is a really very bad idea since hyperref must be loaded after most packages to operate correctly.
So IMHO the only proper solution would be rewriting the document class, it should either not load the hyperref package or at least offer an option to suppress the loading of the hyperref package, so one can load it for oneself later on.
If you comment out the loading of caption, the link works as expected.
No, it's wrong in this case, too, since the hyper link jumps to the first line of the algorithm (=contents of the floating environment) and not to the top of the floating environment.
For having a really correct hyper link one need to include the float package before hyperref, as mentioned in the hyperref README:
Code: Select all
\documentclass[a4paper]{book}
\usepackage[centerlast,small,sc]{caption} % Loaded by Thesis.cls
\usepackage{float}
\usepackage{hyperref} % Loaded by Thesis.cls
\usepackage{algpseudocode}
\usepackage{algorithm}
\begin{document}
\tableofcontents
\chapter{One}
\begin{algorithm}
\caption{Iris Detection Algorithm}\label{alg:myaaa}
\begin{algorithmic}[1]
\State $a=b+c$
\If {$a>2$}
\State \ldots
\EndIf
\end{algorithmic}
\end{algorithm}
\chapter{Two}
See Algorithm~\ref{alg:myaaa}.
\end{document}
Since sommerfee is the author of caption, I hope he can provide a fix.
Fixing incorrect load orders of packages is a very nasty job. Beside the hyperref package, the caption package supports (and patches) 16 packages. Can you imagine how much work it would be dealing with incorrect package load orders additionally? So to make my life simple (means: needing only about 700 lines of code for this) I have to assume that the load order is correct.
And what should the caption package exactly do if it detects an incorrect load order? Correct all problems because of wrong hyperref load order? IMHO this would be a job of a package called "generic_hyperref_load_order_fix" [1], and not of the caption package.
[1] Although writing such package looks like a good idea if would be impossible to do so.