알고리즘을 참조할 수 없습니다.

알고리즘을 참조할 수 없습니다.

어떤 이유로 알고리즘을 참조하면 실제 알고리즘 번호 대신 항상 0이 표시됩니다. 참조가 작동하므로 이를 클릭하면 알고리즘으로 이동됩니다.

\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}

답변1

\label바로 다음에 옵니다 \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}

답변2

\label다음 바로 뒤에 배치하세요 \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}

제가 보여드린 예에서는 \autoref알고리즘 참조와 함께 사용하는 방법도 나와 있습니다.

여기에 이미지 설명을 입력하세요

관련 정보