# hypertarget seems to aim a line too low

\documentclass[a4paper,12pt]{article}
\usepackage[pdfstartview=FitH]{hyperref}
\usepackage{bookmark}
\begin{document}
we want to go\hypertarget{t1}{} 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}
\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\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).

• \makeatletter is somewhat tricky. Basically, you should define your macro like \makeatletter\newcommand{nop}{\Hy@raisedlink{...}}\makeatother. Think of the \makeatletter...\makeatother pair as an environment in which it is acceptable to use @ in macros. – Ryan Reich May 3 '11 at 18:01
• Interestingly, because of the way TeX parses its input, even if you have a macro (such as \nop) whose contents contain @'s in other macros, it is usable anywhere, as long as its own name has only letters. – Ryan Reich May 3 '11 at 18:10
• This is easy. Just put \hypertarget{}{} one line above where you actually want \hyperlink{}{} to hit. – user109740 Jul 9 '16 at 11:03
• I have a similar question and answer here. – James Ray Jan 26 '18 at 16:26

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:

\documentclass{article}
\usepackage{hyperref}

\makeatletter
\makeatother

\begin{document}

Here are targets created
\makeatletter
\makeatother
and \linkdest{t2}indirectly.  Here is one created by \hypertarget{t3}{}hypertarget.

\end{document}


The first two links should point above their targets, and the third one should point to its baseline.

• I dont understand. Is \Hy@raisedlink supposed to replace \hyperref or \bookmark? It sounds like the latter but I didnt find any examples. – peter May 2 '11 at 15:50
• @peter: No, it's a modifier. You use it like this: \makeatletter \Hy@raisedlink{\hypertarget{target}{}} \makeatother, and the link is raised like in Bruno's answer. However, the second argument of \hypertarget should be empty (also like in Bruno's answer), or else the contents will also be raised. Basically, don't use this command, but do what Bruno did. However, some hyperref macros, such as \phantomsection, do call it internally, and produce correctly raised links. – Ryan Reich May 2 '11 at 16:59
• thanks. it's in the \hyperref package, right? because when I use it I get undefined control sequence errors whereever my macro containing it appears. also @raisedlink appears in the output file. – peter May 3 '11 at 6:26
• @peter: Yes, you have to load hyperref (the Hy@ prefix is its personal namespace). Also, if you use it within a document, you have to wrap the whole expression in \makeatletter...\makeatother like I did, so that @ will be considered part of the macro name. If you are getting @raisedlink in the output, it sounds like this is the reason. – Ryan Reich May 3 '11 at 14:12
• i put it in a minimal example, see edited question. it works if i insert it directly, but it doesnt if i put it inside a macro (which is unfortunately my intended use). i'd like it if you could have a look at that. – peter May 3 '11 at 17:53

I remember having the same problem (and failing to get a good solution). A clunky way is to raise the target by hand with \raisebox (from the graphicx package, I believe).

\documentclass{article}
\usepackage{hyperref}
\usepackage{graphicx}
\begin{document}
If we try to go \hypertarget{t1}{here}, this fails
(it bring us at the bottom of the word here''),

If we use some dirty code to raise the
target\raisebox{\ht\strutbox}{\hypertarget{t2}{}},  %%
then we will go to the right place. A \verb|\strut|
is a zero-width object whose height above the baseline
and depth below the baseline are such that it spans
the line completely from top to bottom. Then \verb|\ht\strutbox|
gives the height of such a \verb|\strut|, and our

• I had heard about such hacks, thanks for this concrete example. I am using it now and it works mostly. I still think I am missing something here (or is it really the purpose of \hypertarget to mark the bottom of it's target?), so I will still wait a bit until I accept this as answer (which will, I assume, discourage others from answering more). – peter May 1 '11 at 14:29
Sorry to violate guidelines, but I don't yet have enough reputation to comment. The problem that \Hy@raisedlink may wind up at the end of the previous page seems significant to me. The problem that \raisebox looking bad because it is too close to the top of the line can be solved by using a coefficient: \raisebox{1.2\ht\strutbox} looks pretty good to my eye.