当我单击使用 hyperref 包创建的单词的链接时,如果该单词位于行的中间,则我将被定向到链接下方文本中的行。如果我创建指向该行第一个单词的链接,则我将被定向到正确的行。这是预期的行为吗?这肯定不是最佳的。除了确保链接的单词是行中的第一个之外,有人知道其他解决方法吗?以下是示例:
\documentclass{minimal}
\usepackage{lipsum}
\usepackage{color}
\usepackage{hyperref}
\setlength{\parindent}{0pt}
\begin{document}
\lipsum[1]
The target is \hypertarget{target}{\textcolor{red}{here}}.
\lipsum[2]
This is a \hyperlink{target}{\textcolor{blue}{link}}.
\lipsum[3]
\hypertarget{newtarget}{\textcolor{red}{Here}} is a new target.
\lipsum[4]
This is a new \hyperlink{newtarget}{\textcolor{blue}{link}}.
\end{document}
答案1
你可能会发现这很有用。
\documentclass{minimal}
\usepackage{lipsum}
\usepackage{color}
\usepackage{graphicx}
\usepackage{hyperref}
\setlength{\parindent}{0pt}
\newcommand{\raisetarget}[2]% #1 = label, #2 = contents
{\bgroup
\sbox0{#2}%
\raisebox{\ht0}{\hypertarget{#1}{}}\usebox0%
\egroup}
\begin{document}
\lipsum[1]
The target is \raisetarget{target}{\textcolor{red}{here}}.
\lipsum[2]
This is a \hyperlink{target}{\textcolor{blue}{link}}.
\lipsum[3]
\raisetarget{newtarget}{\textcolor{red}{Here}} is a new target.
\lipsum[4]
This is a new \hyperlink{newtarget}{\textcolor{blue}{link}}.\strut% no descenders
\raisetarget{anothertarget}{\includegraphics[scale=0.5]{example-image}} is a another target.
This is another \hyperlink{anothertarget}{\textcolor{blue}{link}}.
\end{document}