[Tex/LaTex] Placing \phantomsection in the margin

hyperrefpositioning

I am searching for a way to have a command, say \AP (anchor point), that puts a \phantomsection (or anything else) at the left of the current position, say 1 cm to the left of the current column.

The reason for that is that when a reference is used (on a pdf viewer executed with a small screen or a high zoom), a \phantomsection located in the middle of the line yields jumps to location inside the column, for which only part of the column is visible. The proper location would be to have the viewer have the upper left corner of the screen at the left of the column.

It is in some sort a very simple variant of marginpar but not involving the floating mechanisms.

Best Answer

With pdflatex you can use the pre extension of \vadjust to insert the \phantomsection just before the current line of the vertical list. Here shown in an example with two columns:

\documentclass[twocolumn]{article}

\usepackage{hyperref}
\usepackage{blindtext}

\begin{document}
\section{Test}
Here\vadjust pre {\phantomsection}\label{test:a} \blindtext
\Blindtext[2]

And somewhere in this line of text
here.\vadjust pre {\phantomsection}\label{test:b} 
\blindtext

\Blindtext

Goto first \ref{test:a} or second \ref{test:b}.
\end{document}
Related Question