Graphics, Figures & Tablescross-reference to cell inside table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
fatra2
Posts: 126
Joined: Fri May 01, 2009 1:43 pm

cross-reference to cell inside table

Post by fatra2 »

Hi there,

I have a document with a very, very long table, over many pages. Therefore, making a reference to this table is quite ridiculous.

Is there a way to make a reference to a particular cell/row in LaTeX???

I tried making sections and subsections inside the table, but the compiler complains.

Thank you in advance. Cheers

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

cross-reference to cell inside table

Post by localghost »

The complaint is no surprise. But you need a command that generates an anchor for the reference. I'm not aware of a method to do that inside a table.

But I can offer a workaround. You could mark a single cell or a row with a certain color by using the colortbl package. A small colored box in the describing text could be done with pgf/tikZ as some kind of reference. Consider the following example.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\usepackage{array,multirow}
\usepackage[svgnames,table]{xcolor}
\usepackage{tikz}
\usepackage{blindtext}

\parindent0em

\begin{document}
  \blindtext

  \begin{table}[!ht]
    \caption{A table with a colored row for reference}\label{tab:colorrow}
    \centering
    \begin{tabular}{*{4}{c}} \hline
      Some Text & Some Text & Some Text & Some Text \\ \hline
      Some Values & Some Values & Some Values & Some Values \\
      Some Values & Some Values & Some Values & Some Values \\
      \rowcolor{gray!25}
      Some Values & Some Values & Some Values & Some Values \\
      Some Values & Some Values & Some Values & Some Values \\
      Some Values & Some Values & Some Values & Some Values \\
      Some Values & Some Values & Some Values & \cellcolor{gray!50} Some Values \\ \hline
    \end{tabular}
  \end{table}

  As seen in Table~\ref{tab:colorrow}, the values of a row could be referenced by color marks (\,\tikz\fill[gray!25] (0,0) rectangle (16pt,8pt);\,). Even single cells could be pointed out (\,\tikz\fill[gray!50] (0,0) rectangle (16pt,8pt);\,).

  \medskip
  \blindtext
\end{document}
The xcolor package has many more predefined colors. So you won't run out of stuff for your colored references.


Best regards
Thorsten
fatra2
Posts: 126
Joined: Fri May 01, 2009 1:43 pm

Re: cross-reference to cell inside table

Post by fatra2 »

Hi there,

Thank you for your proposition, but this is not precisely what I want. But through your comments, I search some more, and found a solution that suits me very well.

Everyone using LaTeX knows that you can label any part of text where LaTeX generates a number, like a table, equation, section... But my problem is that I want to make a reference to part of a table, which I cannot create a section from within.

My solution is to use the \phantomsection \label{mylabel} anywhere in my table. The \phantomsection is part of the hyperref package, and generates a phanton section (duh!!!) within my table.

It seems to work well. Cheers
Post Reply