如果我有这个代码
\begin{algorithm}
\label{alg:the_alg}
\begin{algorithmic}[1]
\STATE operation 0
\STATE operation 1
\end{algorithmic}
\end{algorithm}
我可以引用。但是,我如何在中alg:the_alg
引用?STATE
algorithmic
答案1
您可以使用与常规标签相同的技术。引用将指向内部的行号algorithmic
:
\documentclass{article}
\usepackage{algorithm,algorithmic}% http://ctan.org/pkg/algorithms
\begin{document}
\begin{algorithm}
\caption{This is an algorithm}
\label{alg:the_alg}
\begin{algorithmic}[1]
\STATE operation 0 \label{op0}
\STATE operation 1 \label{op1}
\end{algorithmic}
\end{algorithm}
See Algorithm~\ref{alg:the_alg}. More specifically, Operation~\ref{op1}.
\end{document}
考虑使用兼容的(现代化的)algorithmicx
捆提供algpseudocode
。这是上述 MWE 的副本,现在包含更新的algpseudocode
包:
\documentclass{article}
\usepackage{algorithm,algpseudocode}
\begin{document}
\begin{algorithm}
\caption{This is an algorithm}
\label{alg:the_alg}
\begin{algorithmic}[1]
\State operation 0 \label{op0}
\State operation 1 \label{op1}
\end{algorithmic}
\end{algorithm}
See Algorithm~\ref{alg:the_alg}. More specifically, Operation~\ref{op1}.
\end{document}