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.