
Aus irgendeinem Grund wird bei der Referenzierung eines Algorithmus immer 0 statt der tatsächlichen Nummer des Algorithmus angezeigt. Referenzen funktionieren, ich kann darauf klicken und werde zum Algorithmus weitergeleitet.
\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}
Antwort1
\label
geht direkt nach \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}
Antwort2
Platzieren Sie \label
unmittelbar danach \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}
Im Beispiel habe ich auch gezeigt, wie man es \autoref
mit Algorithmusreferenz verwendet.