TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to link to a specific row in a Longtabl environment. This is usefull when using the hyperref package and allows the viewer to simply jump from somewhere in the document to the right row of the table. At the moment one jumps always to the top of the column?

For instance:


As one can see in \hyperref[r3]{row 3}...
share|improve this question
Not a possible duplicate, in my view: the older question asks about auto-numbering lines in a table, whereas the new one (I believe) is asking about providing a hyperlink to a specific row of a table. – Mico May 8 '12 at 14:02
@Mico, yes, the wording is not the same, but I am guessing that the OP does not have a label referencing a certain row, I am guessing that the jump to the top of the table is due to \label referencing the \caption of the float and not the row. Otherwise the link would have been correct, as in the linked question. OP, please correct me if I am wrong. I have also asked the OP in the linked question to make the title more general. – zeroth May 8 '12 at 14:08
I hope my edit solves the problem? – Willem Van Onsem May 8 '12 at 14:31
zeroth -- I guess the two issues that distinguish the new question are (i) the explicit requirement to use the hyperref package and (ii) no apparent need for auto-numbering (and auto-labeling) all rows of the given tabular (or longtable) environment. The code given in your answer to the older question will work for the new question, provided one adds a \phantomsection command before each automatically generated \label; otherwise, hyperref will "anchor" all auto-generated label to the top of the environment in question. Why don't you post that as a separate answer to the new question? – Mico May 8 '12 at 14:35
@CommuSoft: if you add a \phantomsection command in front of each \label command in your code, things should work fine. If you need to have links only to certain rows of the table, take a look at my answer for a possible solution. – Mico May 8 '12 at 14:37
up vote 3 down vote accepted

Have a look at the macros \hypertarget and \hyperlink of the hyperref package.

One can create an internal link (almost) anywhere in the document -- including some row in a tabular environment -- with the instruction


where <name> should be a unique "label" that will be used by hyperref to create the "target" and <text> should be whatever should be placed there. E.g., in a tabular environment, <text> could be the content of the first cell of a certain row. You can then link to that "label" elsewhere in the document with the command


where <name> should be the label you chose in the \hypertarget command and <text> can be anything that passes TeX's syntax rules; e.g., it could be the string "there".

share|improve this answer

If you always wish to refer to explicit rows in the text (by text) it seams obvious that you will not change your table often. Therefore you can automate the referencing using Mico's suggestions.

I have created a new table environment which automatically creates labels for the tables according to a user defined prefix, furthermore there is a correction to the anchor placement to enable the correct linking:

\begin{refltable}{<table format>}{<ref prefix>}

This can be used in the following way:


% New environment for the longtable, this will set it up correctly
    \begin{longtable}{>{\stepcounter{tablerowno}\raisebox{\f@size pt}{\phantomsection}\label{#2\thetablerowno}}#1}}%
% In order for the link to pop-up the correct row we have to raise
% the anchor of the link, this is done using the size of the font (\f@size).
% This will also capture \Huge, \LARGE, etc.


  Content of row 1 \\
  Content of row 2 \\  Content of row 3 \\
  Content of row 4 \\  Content of row 5 \\
  Content of row 6 \\  Content of row 7 \\
  Content of row 8 \\  Content of row 9 \\
  Content of row 10\\
  Content of row 11\\
  Content of row 12
As one can see in \hyperref[r10]{row 10} and \hyperref[r1]{row 1}.

  Content of row 1 \\
  Content of row 2 \\  Content of row 3 \\
  Content of row 4 \\  Content of row 5 \\  
  Content of row 6 \\  Content of row 7 \\  
  Content of row 8 \\  Content of row 9 \\  
  Content of row 10\\
  Content of row 11\\
  Content of row 12
As one can see in \hyperref[secr10]{row 10} and \hyperref[secr1]{row 1} together with \hyperref[r1]{row 1} of the first table.


However, you might be better off by using the manual way by Mico as it would ensure that you dont accidentally reference a wrong row in the table.

share|improve this answer
Very nice! A completely separate issue: I've noticed that both your solution (which uses LaTeX labels and explicit \phantomsection commands) and my method (which uses \hypertarget and \hyperlink directives) tend to produce the following odd/unexpected behavior, in both tabular and longtable environments: When one clicks on the hyperlink, the pdf reader doesn't "jump" to the row being cross-referenced but to the subsequent row. I wonder if this might be a bug in hyperref. – Mico May 8 '12 at 15:56
@Mico I have seen this several times. It happens all the time when one uses \phantomsection. I also see it when I manually add sections for bibliography etc. It appears that the phantom section has difficulties in placing the anchor correct. However, I have never considered it a bug, it might be one?!? :) – zeroth May 8 '12 at 17:26
@Mico it certainly is due to the placement of the anchor being located on the baseline of the line. I realised this last night right before I fell asleep! Try my updated version of the code which raises the phantomsection to the current font height! :) – zeroth May 9 '12 at 6:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.