[Tex/LaTex] Referencing to table cell in Latex

cross-referencinglabelstables

I'm working on a table in LaTeX which contains a reference, a formula and the number of the formula in 3 columns. There are also formulas in the text and the ones in the table should be serially numbered (so if in the text there was '(1)', then in the table the next formula is '(2)').

Here is my table. The third column is the equation number (I found this piece of code after some research on the internet):

\begin{table}[htbp]
   \centering
   \caption{Test Caption.}
\begin{tabular}{llc}
    \hline
    \textbf{reference} & \textbf{correlation} \\
    \hline
    reference 1        & $a = b$  
                       & \stepcounter{equation}(\theequation) 
    \\
\hline
\end{tabular}
\label{tab:test}
\end{table}

My question: How can I reference on the formula in the table in the text? I tried it with a \label{...} command but it didn't give the right formula number. Then I tried the phantomsection command (in the cell with the formula & the equation number)

\phantomsection \label{xxx}

which allowed to jump to somehow the right place but the equation numbering in the text was not correct.

Is it possible to reference in the text to this equation and have the correct equation number?

The output should then be somehow like this: "As it is seen in Eq.(xxx)…" where xxx is the number of the equation in the table.

Best Answer

You need \refstepcounter here. This not only steps the counter (similar to \stepcounter), but also updates the reference (stored in \@currentlabel):

enter image description here

\documentclass{article}

%\usepackage{hyperref}
\usepackage{amsmath}

\begin{document}

\begin{equation}
  f(x) = ax^2 + bx + c
\end{equation}

See Table~\ref{tab:test} and equation~\eqref{eq:tbl}.
\begin{table}
  \centering
  \caption{A table caption.}\label{tab:test}
  \begin{tabular}{llc}
    \hline
    \textbf{reference} & \textbf{correlation} \\
    \hline
    reference 1        & $a = b$  
                       & \refstepcounter{equation}(\theequation)\label{eq:tbl}
    \\
    \hline
  \end{tabular}
\end{table}

\end{document}

Note how the able example also highlights the problems you might be facing with manually setting an reference that is part of a float. The label may appear out-of-sequence with the rest of the text (where (2) appears before (1)).

The above example will also work with hyperref.

Related Question