Take the 2-minute tour ×
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.

I have a table with many entries and I want to reference the key so another person can quickly look up what the key means.

Here is some pseudocode:

Table
snippet1\label{?key1} & longexplanatory text
snippet2\label{?key2} & longexplanatory text
snippet3\label{?key3} & longexplanatory text

connect \ref{key1} with \ref{key13}

After compilation I want the text to read

connect snippet1 with snippet3

The reader should be able to quickly jump to the table when clicking on snippet-N.

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

The following uses \refstepcounter (instead of the internal \@currentlabel) of a dummy counter to make the text to something that can be referenced. \raisebox moves \refstepcounter a bit to move the anchor position, if package hyperref is used. At the place of \refstepcounter hyperref sets the anchor.

\documentclass{article}
\newcounter{keylabel}
\newcommand*{\keylabel}[2]{%
  \leavevmode
  \raisebox{2ex}[0pt][0pt]{%
    \renewcommand*{\thekeylabel}{#1}%
    \refstepcounter{keylabel}%
    \label{#2}%
  }%
  #1%
}

\usepackage{hyperref}

\begin{document}
\begin{tabular}{@{}ll@{}}
\keylabel{snippet1}{key1} & longexplanatory text\\
\keylabel{snippet2}{key2} & longexplanatory text\\
\keylabel{snippet3}{key3} & longexplanatory text\\
\end{tabular}

connect \ref{key1} with \ref{key3}
\end{document}

Result

share|improve this answer
add comment

Your Answer

 
discard

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.