[Tex/LaTex] Customized cleveref

cleverefcross-referencinghyperref

How can I customize the cleveref package such that when I type

\begin{equation}
A = B
\label{eqn:test}
\end{equation}

\cref{eqn:test}

then the output is

Eq. (1)

where Eq. is black and (1) is blue with hyperlink?

Best Answer

For those that like colourful links etc. ;-)

Label formats for individual counter types can be changed with \creflabelformat{counter type}{#2Y#3} where Y stands for some formatting code with should contain the parameter #1

#2 and #3 are used by the hyperanchors and must appear in this order -- do not change or remove this!

As can be detected from the screen shot the cross-reference format for the table counter is not affected by this.

\documentclass{article}

\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{hyperref}

\usepackage{cleveref}

\creflabelformat{equation}{#2{\color{blue}(#1)}#3}

\begin{document}

\begin{equation}
A = B
\label{eqn:test}
\end{equation}
\begin{table}
\caption{Foo} \label{foolabel}
\end{table}
\clearpage

\cref{eqn:test} or \Cref{eqn:test} but \cref{foolabel}\dots
\end{document}

enter image description here