如何更改交叉引用的颜色,我希望标签为黑色,数字为蓝色,如图所示
\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{caption}
\begin{document}
Insert cross reference \autoref{figure}
\begin{figure}%h!
\centering
\includegraphics[]{example-image-a}
\caption{Validation procedure for LR model}\label{figure}
\end{figure}
\end{document}
答案1
我认为需要做好三件事:
- 定义你的蓝色。
- 为 hyperref 的
linkcolor
-key 分配您定义的蓝色。 \HyRef@testreftype
在传递引用的名称/类型之前,修补程序将采用当前文本颜色。
\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\definecolor{mylinkcolor}{rgb}{0.561, 0.667, 0.863}
\usepackage[colorlinks=true, linkcolor=mylinkcolor]{hyperref}
\makeatletter
\newcommand\MyAutoefPhrasecolorGroup[1]{%
\color@begingroup\color{MyCurrentcolor}#1\endgroup
}%
\def\HyRef@testreftype#1.#2\\{%
\colorlet{MyCurrentcolor}{.}%
\ltx@IfUndefined{#1autorefname}{%
\ltx@IfUndefined{#1name}{%
\HyRef@StripStar#1\\*\\\@nil{#1}%
\ltx@IfUndefined{\HyRef@name autorefname}{%
\ltx@IfUndefined{\HyRef@name name}{%
\def\HyRef@currentHtag{}%
\Hy@Warning{No autoref name for `#1'}%
}{%
\edef\HyRef@currentHtag{%
\noexpand\MyAutoefPhrasecolorGroup{%
\expandafter\noexpand\csname\HyRef@name name\endcsname
}%
\noexpand~%
}%
}%
}{%
\edef\HyRef@currentHtag{%
\noexpand\MyAutoefPhrasecolorGroup{%
\expandafter\noexpand
\csname\HyRef@name autorefname\endcsname
}%
\noexpand~%
}%
}%
}{%
\edef\HyRef@currentHtag{%
\noexpand\MyAutoefPhrasecolorGroup{%
\expandafter\noexpand\csname#1name\endcsname
}%
\noexpand~%
}%
}%
}{%
\edef\HyRef@currentHtag{%
\noexpand\MyAutoefPhrasecolorGroup{%
\expandafter\noexpand\csname#1autorefname\endcsname
}%
\noexpand~%
}%
}%
}%
\makeatother
\usepackage{caption}
\begin{document}
{\bfseries\verb|\autoref|-references with hyperlink:}
Textcolor unchanged: Insert cross reference \autoref{figure}
Textcolor sawitched to green: \textcolor{green}{Insert cross reference \autoref{figure}}
{\bfseries\verb|\autoref*|-references without hyperlink:}
Textcolor unchanged: Insert cross reference \autoref*{figure}
Textcolor sawitched to green: \textcolor{green}{Insert cross reference \autoref*{figure}}
\begin{figure}%h!
\centering
\includegraphics[]{example-image-a}
\caption{Validation procedure for LR model}\label{figure}
\end{figure}
\end{document}
对于\autoref
带有超链接的引用,短语“图”会以周围文本的颜色出现,并且可以点击,就像以 hyperref 的键表示的颜色出现的数字一样linkcolor
。