I would like to use \ref and \label for two lines in a table, which can be done using \phantomsection:
\documentclass{article}
\usepackage{hyperref}
\usepackage{lipsum}
\begin{document}
Cross-references to line \ref{line:x} and line
\ref{line:y} and \ref{line:z}.
\makeatletter
\begin{tabular}{ll}
\phantomsection\edef\@currentlabel{$x$}\label{line:x} Line $x$ & $\frac{1}{2}$ \\
\phantomsection\edef\@currentlabel{$y$}\label{line:y} Line $y$ & $\frac{3}{4}$ \\
\end{tabular}
\phantomsection\edef\@currentlabel{$z$}\label{line:z}Line $z$. This one works.
\lipsum
\end{document}
The problem is that when clicking on the $x$ and $y$ framed in red at the top, the PDF reader is sent to the baseline of the targetted line, while the \phantomsection at the beginning of a paragraph works:

It is clearly visible that the PDF reader is sent at the vertical position of the fraction bars, and not at the top of the line.
How can I get the hyperref anchor at the top of the line, and not on the baseline?
Below is a screenshot of the whole document:

I could hack and put the \phantomsection on the preceeding line, but that won't take into account deep lines (with lots of stuff below the baseline).
I tried messing around with \begin{minipage}[t] or with negative \vspace but still can't get rid of that misalignment.
\phantomsectionjust as a shorthand to avoid using a dummy counter and have a shorter MWE. Your code exhibits the exact same problem as mine, when compiled usingpdflatex, namely the\ref{line:x}points to the baseline ofLine $x$, not to the top of the line. – Suzanne Soy May 19 '15 at 18:25\customlabel{the-label}{the-name}macro I wrote to be able to use\ref{the-label}and have it showthe-name, for referencing small parts of a figure or table (on line $a$, we see that… on line $b$, blah blah), but with the safety net that if I rename/renumber/reorder my labels in the table or figure, they will automatically be changed in the paragraphs containing references to them. – Suzanne Soy May 19 '15 at 18:41Nwhich does the line numbering automatically – Jan 03 '16 at 00:48\labelmust be placed in the line number cell still, due to grouping. – Jan 03 '16 at 01:04\newcounter{foo}\usepackage{array} \newcolumntype{N}{>{\refstepcounter{foo}\thefoo}r}, for example – Jan 03 '16 at 01:14hyperrefshould point the label position correctly (in OP solution it miss for one line). This my solution in proposed in Edit quite well fulfill. – Zarko Jan 03 '16 at 02:01