在算法环境中标记特定状态

在算法环境中标记特定状态

如果我有这个代码

\begin{algorithm}
  \label{alg:the_alg}
  \begin{algorithmic}[1]
    \STATE operation 0
    \STATE operation 1
  \end{algorithmic}
\end{algorithm}

我可以引用。但是,我如何在中alg:the_alg引用?STATEalgorithmic

答案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}

相关内容