Graphics, Figures & TablesReferencing a row in a table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
isharp2
Posts: 23
Joined: Fri Feb 11, 2011 2:06 am

Referencing a row in a table

Post by isharp2 »

Hi,
I would like to reference a row in a table. Where, for example, the 3rd row of table 2 would output [2.3].

Below is some code that sets up a counter and outputs the references and outputs the row of the table, but does not preface it with the table number.

Code: Select all

\documentclass{article}
\usepackage{tabularx}
\usepackage{hyperref}


\newcounter{rownumber}[figure] 
\setcounter{rownumber}{1}

\begin{document}


\section{A section}
This is just some random text\dots

\subsection{A Sub-section}
\subsection{Another Sub-section}

\begin{figure}[h!]
\caption{is here}
\begin{tabular}{| c | c | c | }

\refstepcounter{rownumber}
 \label{r1} 1 & my first row & some text \\
\refstepcounter{rownumber}
\label{r2}  2 & my second row & some other text \\
\refstepcounter{rownumber}
\label{r3}  3 & third row & final text \\ 
\end{tabular}
\end{figure}

\subsection{A Sub-Phase}
\section{YYYY}
YYYY
\section{ZZZZZZZZ}

The rownumber is \hspace{\value{rownumber}\parindent}

\subsection{A Sub-Phase}

1st Reference: \ref{r1}\\
Second Reference: \ref{r2}\\
Third Reference: \ref{r3}\\

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Referencing a row in a table

Post by Juanjo »

Perhaps it would suffice to add the following line after the corresponding \newcounter command:

Code: Select all

\renewcommand{\therownumber}{\thefigure.\arabic{rownumber}}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
isharp2
Posts: 23
Joined: Fri Feb 11, 2011 2:06 am

Re: Referencing a row in a table

Post by isharp2 »

perfect! Thanks for you reply.
Post Reply