我尝试使用hyperref
包将来自的内部链接着色\label
为绿色,而将来自锚文本的内部\hypertarget
链接着色为红色。但是,在这两种情况下,相关文本都显示为绿色?我正在使用revtex4-1
,但我不认为这是问题所在……
\documentclass[a4paper]{revtex4-1}
\usepackage[pdftex]{xcolor}
\usepackage[pdftex,breaklinks,colorlinks,
linkcolor=green,
anchorcolor=red]{hyperref}
\begin{document}
\begin{equation}
\text{this is an equation} \label{theeq}
\end{equation}
This is the equation \ref{theeq} and it is green as expected.\\
\hypertarget{thelink}{This should be anchored}
\hyperlink{thelink}{ But its color is not red?}
\end{document}
答案1
好吧,我想你应该将这个错误报告给的维护者hyperref
。
在问题得到解决之前,您可以使用以下解决方法:
\newcommand{\myhypertarget}[3][red]{\hypertarget{#2}{\textcolor{#1}{#3}}}%
命令手动\myhypertarget
将颜色设置red
为目标文本。
使用以下 MWE
\documentclass[a4paper]{revtex4-2}
\usepackage{xcolor}
\usepackage[%
breaklinks,
colorlinks,
linkcolor=green,
anchorcolor=red
]{hyperref}
\newcommand{\myhypertarget}[3][red]{\hypertarget{#2}{\textcolor{#1}{#3}}}%
\begin{document}
\begin{equation}
\text{this is an equation} \label{theeq}
\end{equation}
This is the equation \ref{theeq} and it is green as expected.\\
\hypertarget{thelink}{This should be anchored}
And this is with \texttt{\\myhypertarget}:
\myhypertarget{thelink1}{This should be anchored}
Text between target and link. Text between target and link.
Text between target and link. Text between target and link.
\hyperlink{thelink}{ But its color is not red?}
\hyperlink{thelink1}{ But its color is not red?}
\end{document}
得到结果:
请注意,我删除了和pdftex
的驱动程序。我还使用了类,即 revtex 的当前版本。xcolor
hyperref
revtex4-2