2

I'm trying to emphasize my figure references with bold text. When referencing a labeled figure with \cref{fig:mylabel} I get the correct text Abbildung 1, however I'm having trouble formatting it.

enter image description here

I'm using the packages hyperref and cleveref with a German document setting. As per documentation there is the option \crefdefaultlabelformat, however when I try to make the entire label bold (so including the name) with \crefdefaultlabelformat{\bfseries#2#1#3} only the number reference will get emphasized. Same is true for \creflabelformat{figure}....

There is also the option to format the links provided by hyperref, but I was unable to find something that only targets these specific links.

\documentclass[ngerman]{article}
\usepackage{babel}
\usepackage[labelfont=bf]{caption}
\usepackage[colorlinks]{hyperref}
\usepackage[noabbrev, nameinlink]{cleveref}
\crefdefaultlabelformat{\bfseries#2#1#3}

\begin{document}
\begin{figure}[h]
    \caption{Some image}
    \label{fig:mylabel}
\end{figure}

This should all be bold \(\rightarrow\) \cref{fig:mylabel}
\end{document}

2 Answers 2

3

If the aim is to have just figure references bold, you can do

\documentclass[ngerman]{article}
\usepackage{babel}
\usepackage[labelfont=bf]{caption}
\usepackage[colorlinks]{hyperref}
\usepackage[noabbrev, nameinlink]{cleveref}

\crefformat{figure}{#2\bfseries\figurename~#1#3}

\begin{document}

\begin{figure}[htp]
    \caption{Some image}
    \label{fig:mylabel}
\end{figure}

This should all be bold \cref{fig:mylabel} and this shouldn't.

\end{document}

If you really want all \cref produced text to be in boldface, you can patch \@cref.

\documentclass[ngerman]{article}
\usepackage{babel}
\usepackage{xpatch}
\usepackage[labelfont=bf]{caption}
\usepackage[colorlinks]{hyperref}
\usepackage[noabbrev, nameinlink]{cleveref}

\makeatletter
\xpatchcmd{\@cref}{\begingroup}{\begingroup\bfseries}{}{}
\makeatother

\begin{document}

\begin{figure}[htp]
    \caption{Some image}
    \label{fig:mylabel}
\end{figure}

This should all be bold \cref{fig:mylabel} and this shouldn't.

\end{document}

enter image description here

1
  • This makes the conjunctions bold as well when using multi-references. Is there a way to make only the labels bold? Commented Mar 11 at 19:55
1

Perhaps someone has a more cref/hyperref native solution.

But in the meanwhile what works is to just wrap cref with bfseries. Inspired by Werner's answer to make it a bit less cumbersome, we can automatize this wrapping by first saving the cref under another name e.g. oldcref:

\usepackage{letltxmacro}
\LetLtxMacro\oldcref\cref

And then redefining the cref with the wrapped one:

\usepackage{xparse}
\RenewDocumentCommand{\cref}{m}{\bfseries\oldcref{#1}} % m here means one mandatory argument

All together for your MWE:

\documentclass[ngerman]{article}
\usepackage{babel}
\usepackage[labelfont=bf]{caption}
\usepackage[colorlinks]{hyperref}
\usepackage[noabbrev, nameinlink]{cleveref}

% simply wrap cref by bfseries
\usepackage{letltxmacro,xparse}
\LetLtxMacro\oldcref\cref
\RenewDocumentCommand{\cref}{m}{\bfseries\oldcref{#1}}


\begin{document}
\begin{figure}[h]
    \caption{Some image}
    \label{fig:mylabel}
\end{figure}

This should all be bold \(\rightarrow\) \cref{fig:mylabel}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .