表格和算法中的交叉引用问题

表格和算法中的交叉引用问题

我在交叉引用方面遇到了问题,但一直没能解决。我有一个表格和一个算法,但无法引用。然而,这两种情况下的行为是不同的:当我尝试引用表格时,LaTex 会产生 ??,而对于算法,会产生一个空格。

我在这里附上了 LaTeX 文档。非常感谢您的帮助。

===========================================

\documentclass[11pt,a4paper]{article}

\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsmath}
\setcounter{tocdepth}{3}
\usepackage{latexsym,epsfig}
\usepackage{graphicx} %To include graphics
\usepackage[usenames,dvipsnames]{color} %To use color
\usepackage[hyphens]{url} %To use links. Option 'hyphens' is good for breaking urls.
\usepackage{enumerate} %To choose enumerator symbols
\usepackage{soul} %To use highlighting of the text
\usepackage{array} %To use arrays
\usepackage{verbatim}
\usepackage[hang,small,bf]{caption}
\usepackage[ruled,linesnumbered]{algorithm2e}  %To create nice algorithms - must be loaded *after* natbib
\usepackage{hyperref}

%------- HEADINGS --------

\title{Test}
\author{Moondog } 
\begin{document}
\maketitle

%%===============================%%

\section{Introduction}
\label{sec:intro}

The process is best described by Algoritm \label{algo:iterated}. 

% -  ALGORITHM --

\begin{algorithm}[ht]
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
%\linesnumbered
%\dontprintsemicolon
%\SetLine
\vspace{.2cm}
\Input{A matrix} 
\Output{A set of matrices} 
\For{$r$:=$1$ \KwTo $N$}{
$B$ := $C$ \;
}  % End of For loop

\caption{Algorithm}
\label{algo:iterated}  
\end{algorithm}
%-------------------  

This process is described schematically in Table~\ref{tab:schematic1}. 

\begin{table}[ht]
  \label{tab:schematic1}
  \centering
  \begin{tabular}{|lcr|}
    \hline
    $\mathbf{Q}^{(1)}_{0,0}$ & $\mathbf{Q}^{(1)}_{1,0}$ & $\mathbf{Q}^{(1)}_{2,0}$ \\
    $\mathbf{Q}^{(1)}_{0,1}$ & $\mathbf{Q}^{(1)}_{1,1}$ & $\mathbf{Q}^{(1)}_{2,1}$ \\
    $\mathbf{Q}^{(1)}_{0,2}$ & $\mathbf{Q}^{(1)}_{1,2}$ & $\mathbf{Q}^{(1)}_{2,2}$ \\
    \hline     
  \end{tabular}
  \caption{Schema}
\end{table}

\begin{thebibliography}{4}
\bibitem{M01} Meyer, C.D.: Matrix Analysis and Applied Linear Algebra. SIAM (2001). 
\end{thebibliography}
\end{document}

答案1

引用是使用计数器值生成的,这些值被写入\label文件.aux,但为了获得正确的标签,\label必须执行命令 \caption,因为该宏确实使用了\refstepcounter,它提供了正确的信息。

此外有两次,在我看来,\label{algo:iterated}第一次出现应该是。\ref{algo:iterated}

\documentclass[11pt,a4paper]{article}

\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsmath}
\setcounter{tocdepth}{3}
\usepackage{latexsym,epsfig}
\usepackage{graphicx} %To include graphics
\usepackage[usenames,dvipsnames]{color} %To use color
\usepackage[hyphens]{url} %To use links. Option 'hyphens' is good for breaking urls.
\usepackage{enumerate} %To choose enumerator symbols
\usepackage{soul} %To use highlighting of the text
\usepackage{array} %To use arrays
\usepackage{verbatim}
\usepackage[hang,small,bf]{caption}
\usepackage[ruled,linesnumbered]{algorithm2e}  %To create nice algorithms - must be loaded *after* natbib
\usepackage{hyperref}

%------- HEADINGS --------

\title{Test}
\author{Moondog } 
\begin{document}
\maketitle

%%===============================%%

\section{Introduction}
\label{sec:intro}

The process is best described by Algoritm \ref{algo:iterated}. 

% -  ALGORITHM --

\begin{algorithm}[ht]
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
%\linesnumbered
%\dontprintsemicolon
%\SetLine
\vspace{.2cm}
\Input{A matrix} 
\Output{A set of matrices} 
\For{$r$:=$1$ \KwTo $N$}{
$B$ := $C$ \;
}  % End of For loop

\caption{Algorithm}
\label{algo:iterated}  
\end{algorithm}
%-------------------  

This process is described schematically in Table~\ref{tab:schematic1}. 

\begin{table}[ht]
  \centering
  \begin{tabular}{|lcr|}
    \hline
    $\mathbf{Q}^{(1)}_{0,0}$ & $\mathbf{Q}^{(1)}_{1,0}$ & $\mathbf{Q}^{(1)}_{2,0}$ \\
    $\mathbf{Q}^{(1)}_{0,1}$ & $\mathbf{Q}^{(1)}_{1,1}$ & $\mathbf{Q}^{(1)}_{2,1}$ \\
    $\mathbf{Q}^{(1)}_{0,2}$ & $\mathbf{Q}^{(1)}_{1,2}$ & $\mathbf{Q}^{(1)}_{2,2}$ \\
    \hline     
  \end{tabular}
  \caption{Schema}
  \label{tab:schematic1}
\end{table}

\begin{thebibliography}{4}
\bibitem{M01} Meyer, C.D.: Matrix Analysis and Applied Linear Algebra. SIAM (2001). 
\end{thebibliography}
\end{document}

相关内容