I made a small example:
\documentclass[a4paper,12pt]{article}
\usepackage[pdfstartview=FitH]{hyperref}
\usepackage{bookmark}
\begin{document}
we want to go\hypertarget{t1}{} here.\\
instead we go here.
\bookmark[dest=t1]{goto 1}
\end{document}
When clicking the bookmark in the PDF file, the second line will be at the top of the screen, but the first one should. What do I understand wrongly? How do I have to do it?
edit: my summary of the answers (I feel that \Hy@raisedlink
looks a bit better since the other one is really close to the top of the line). the problem is: this doesn't seem to work in macros. I always get an 'undefined control sequence' error:
\documentclass[a4paper,12pt]{article}
\usepackage[pdfstartview=FitH]{hyperref}
\usepackage{bookmark}
\newcommand{\linkdest}{\makeatletter\Hy@raisedlink{\hypertarget{t4}{}}\makeatother}
\begin{document}
apparently \textbackslash hypertarget marks the bottom of its line instead
of the top. it can be fixed using \textbackslash Hy@raisedlink or
\textbackslash raisebox (a bit lower).\\\\
we cant go\hypertarget{t1}{} here.\\\\
we can go here\makeatletter\Hy@raisedlink{\hypertarget{t2}{}}\makeatother{}. %
we can go here\raisebox{\ht\strutbox}{\hypertarget{t3}{}} too.\\\\
go here by macro: \linkdest .
\bookmark[dest=t1]{cant}
\bookmark[dest=t2]{can}
\bookmark[dest=t3]{can too}
\bookmark[dest=t4]{macro}
\end{document}
edit 2: OK, it works now. I have noticed that \Hy@raisedlink
seems to pretend that the link was in the line above (e.g. it can go to the end of a page if the marked place is at the beginning of the next) while \raisebox
goes to the top of the current text-line (thereby sometimes cutting big formulas).
Best Answer
This was my very first question here: Hyperlinks to a bibliography are one line off. The reason is that
hyperref
links, like all TeX boxes, are placed on the baseline. There is an internal command\Hy@raisedlink
which does more or less what Bruno's answer describes. Here is an example of its usage both inside and outside macros:The first two links should point above their targets, and the third one should point to its baseline.