TeX - LaTeX Asked by Abdelhak Elfengour on December 11, 2020
How to change the colour of cross-reference, I want the label to be in black and the number in blue as in the image
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}
I think you need to do three things:
linkcolor
-key your defined blue color.HyRef@testreftype
to resort to the current textcolor before delivering the name/type of the reference.
documentclass{article}
usepackage{graphicx}
usepackage{xcolor}
definecolor{mylinkcolor}{rgb}{0.561, 0.667, 0.863}
usepackage[colorlinks=true, linkcolor=mylinkcolor]{hyperref}
makeatletter
newcommandMyAutoefPhrasecolorGroup[1]{%
color@begingroupcolor{MyCurrentcolor}#1endgroup
}%
defHyRef@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}{%
defHyRef@currentHtag{}%
Hy@Warning{No autoref name for `#1'}%
}{%
edefHyRef@currentHtag{%
noexpandMyAutoefPhrasecolorGroup{%
expandafternoexpandcsnameHyRef@name nameendcsname
}%
noexpand~%
}%
}%
}{%
edefHyRef@currentHtag{%
noexpandMyAutoefPhrasecolorGroup{%
expandafternoexpand
csnameHyRef@name autorefnameendcsname
}%
noexpand~%
}%
}%
}{%
edefHyRef@currentHtag{%
noexpandMyAutoefPhrasecolorGroup{%
expandafternoexpandcsname#1nameendcsname
}%
noexpand~%
}%
}%
}{%
edefHyRef@currentHtag{%
noexpandMyAutoefPhrasecolorGroup{%
expandafternoexpandcsname#1autorefnameendcsname
}%
noexpand~%
}%
}%
}%
makeatother
usepackage{caption}
begin{document}
{bfseriesverb|autoref|-references with hyperlink:}
Textcolor unchanged: Insert cross reference autoref{figure}
Textcolor sawitched to green: textcolor{green}{Insert cross reference autoref{figure}}
{bfseriesverb|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}
With autoref
-references with hyperlinks the phrase "Figure" occurs in the color of the surrounding text and is clickable like the number which occurs in the color denoted by hyperref's linkcolor
-key.
Correct answer by Ulrich Diez on December 11, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP