2

I'm trying to change the style of the text of the images reference. I want something like you see in textbooks, for example with the words

(fig. 1.23)

in bold, colored and maybe a different font. So I define a new color

\definecolor{viola}{rgb}{0.42,0.05,0.09}

and try this:

(\textcolor{viola}{\textbf{\textsf{\textbf{fig. \ref{cap1:tree}}}}}).

But what I'm getting is this: enter image description here

How can I change the numbers style as well?

nico
  • 143

1 Answers1

3

This seems like a perfect case for the cleveref package- otherwise you're faced with typing that formatting every time you wish to reference a figure (yikes!).

screenshot

Here's a complete MWE to play with- see the cleveref documentation for further details.

% arara: pdflatex
\documentclass{report}
\usepackage{xcolor}
\usepackage{hyperref}      
\usepackage{cleveref}     

\definecolor{viola}{rgb}{0.42,0.05,0.09}
\crefformat{figure}{\protect\textcolor{viola}{\bfseries\textsf{fig.~#2#1#3}}}
\Crefformat{figure}{\protect\textcolor{viola}{\bfseries\textsf{Fig.~#2#1#3}}}
\begin{document}

\begin{figure}[!htb]
  \centering
  \rule{20pt}{20pt}
  \caption{My figure}
  \label{fig:myfig}
\end{figure}

\begin{itemize}
  \item Use \cref{fig:myfig} mid sentence.
  \item \Cref{fig:myfig} is appropriate for the beginning of a sentence.
\end{itemize}
\end{document}
cmhughes
  • 100,947