4

I have a custom commands for setting up two-way hyperlink/hypertargets:

\documentclass[a4paper]{report}

\usepackage[english]{babel} \usepackage[utf8]{inputenc} \usepackage[hidelinks]{hyperref} \usepackage{acronym} \usepackage{longtable} \usepackage{lipsum}

% Custom Commands \newcommand{\pac}[2]{\hyperlink{{#1}1}{\hypertarget{{#1}0}{#2}}} \newcommand{\jac}[1]{\hypertarget{{#1}1}{\hyperlink{{#1}0}{\ac{#1}}}}

\begin{document}

\chapter{List of Acronyms}

% This table gives me fine control of acronym formatting \begin{longtable}{ p{.20\textwidth} p{.80\textwidth} } \pac{frog}{FROG} & Finite Random Oscillator Response \end{longtable}

% I made up this acronym \acrodef{frog}[FROG]{Finite Random Oscillator Response}

% -----------------------------------------------------

\chapter{First chapter} Get to know more about what is a \jac{frog}. \lipsum[1-10]

\end{document}

But whenever the links appear in the final PDF it always jumps to the line below the target, requiring me to scroll up one line to view the hyperlink. I have spent a while trying to solve this, and I can't seem to find any working solution, I have seen this question - which is the exact issue I am having, but the solution with \phantombreak makes no difference, inserting a \break before partially fixes the issue in that it jumps to the right location, but now there is a huge line break whenever I want to use a hyperlink. Please advise as it is quite an irritating problem.

Edit: Added an example which reproduces the exact problem (verified in overleaf and in the downloaded PDF).

dexteritas
  • 9,161
  • 1
    Make a complete example. That makes it much easier to test your issue. – Ulrike Fischer Jun 03 '20 at 17:23
  • You should look at the hyperref code to see that the links are actually raised to properly show when the target is reached. Provide a minimal example that is complete (starts with \documentclass and ends with \end{document} and replicates your problem) and we'll be able to help you. – Werner Jun 03 '20 at 17:32
  • just working on making a complete example to see if it can be replicated in an empty document. was hoping it would be a quick fix. – Renegade243 Jun 03 '20 at 17:35

1 Answers1

3

You can raise the anchors:

\makeatletter
\newcommand{\pac}[2]{\hyperlink{{#1}1}{\Hy@raisedlink{\hypertarget{{#1}0}{}}{#2}}}
\newcommand{\jac}[1]{\Hy@raisedlink{\hypertarget{{#1}1}{}}{\hyperlink{{#1}0}{\ac{#1}}}}
\makeatother
Ulrike Fischer
  • 327,261