
Por alguma razão, referenciar um algoritmo exibe sempre 0 em vez do número real do algoritmo. As referências funcionam, posso clicar nelas e isso me levará ao algoritmo.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{hyperref}
\begin{document}
\section{Introduction}
It doesn't work \ref{alg1} \ref{alg2}.
\begin{algorithm}
\caption{Algorithm 1}
\begin{algorithmic}[ht]
\label{alg1}
\State it's a test
\end{algorithmic}
\end{algorithm}
\newpage
\begin{algorithm}
\caption{Algorithm 2}
\begin{algorithmic}[ht]
\label{alg2}
\State it's a test
\end{algorithmic}
\end{algorithm}
\end{document}
Responder1
\label
vai diretamente depois \caption
:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{hyperref}
\begin{document}
\section{Introduction}
It doesn't work \ref{alg1} \ref{alg2}.
\begin{algorithm}
\caption{Algorithm 1}
\label{alg1}
\begin{algorithmic}[ht]
\State it's a test
\end{algorithmic}
\end{algorithm}
\newpage
\begin{algorithm}
\caption{Algorithm 2}
\label{alg2}
\begin{algorithmic}[ht]
\State it's a test
\end{algorithmic}
\end{algorithm}
\end{document}
Responder2
Coloque \label
imediatamente depois \caption{…}
:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{hyperref}
\newcommand*{\algorithmautorefname}{Algorithm}
\begin{document}
\section{Introduction}
It does work Algorithm~\ref{alg1} and \autoref{alg2}.
\begin{algorithm}
\caption{Algorithm 1}
\label{alg1}
\begin{algorithmic}[ht]
\State it's a test
\end{algorithmic}
\end{algorithm}
\newpage
\begin{algorithm}
\caption{Algorithm 2}
\label{alg2}
\begin{algorithmic}[ht]
\State it's a test
\end{algorithmic}
\end{algorithm}
\end{document}
No exemplo que também mostrei como usar \autoref
com referência de algoritmo.