I made a small example:

we want to go\hypertarget{t1}{} here.\\
instead we go here.
\bookmark[dest=t1]{goto 1}

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:

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=t3]{can too}

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).

  • 2
    \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, 2011 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, 2011 at 18:10
  • This is easy. Just put \hypertarget{}{} one line above where you actually want \hyperlink{}{} to hit.
    – user109740
    Jul 9, 2016 at 11:03
  • I have a similar question and answer here.
    – James Ray
    Jan 26, 2018 at 16:26

3 Answers 3


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:




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

 \hyperlink{t1}{Here} \hyperlink{t2}{are} \hyperlink{t3}{links}


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, 2011 at 15:50
  • 1
    @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, 2011 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, 2011 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, 2011 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, 2011 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).

If we try to go \hypertarget{t1}{here}, this fails 
(it bring us at the bottom of the word ``here''), 
as you can \hyperlink{t1}{check}.

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
\hyperlink{t2}{link} points to the right place.
  • 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, 2011 at 14:29
  • 4
    @peter: I don't think that you should accept this answer, even after some time: there must definitely be a better answer, and I only posted this to solve your problem in the short term (I'd be happy myself to know a better way). May 1, 2011 at 14:34
  • Unfortunately this breaks formatting in various ways, adding extra space and removing line breaks.
    – Timmmm
    Nov 30, 2021 at 11:40
  • Probably need to add \smash, so \smash{\raisebox{\ht\strutbox}{...}}. Dec 2, 2021 at 11:06

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 of \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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.