6

I am using the cleveref package for cross-referencing. When I use

\cref{tab1} and \cref{fig1}

I got the output as

table 1 and fig. 1

respectively. I would instead like to get

table (1) and fig. (1)

How can I achieve this?

7

You can change the default format using \crefdefaultlabelformat; in your case, you can use

\crefdefaultlabelformat{(#2#1#3)}

A complete example:

\documentclass{article}
\usepackage{cleveref}

\crefdefaultlabelformat{(#2#1#3)}

\begin{document}

\begin{table}
\centering
A
\caption{a test table}
\label{tab:test}
\end{table}
\begin{figure}
\centering
B
\caption{a test figure}
\label{fig:test}
\end{figure}

\cref{tab:test} and~\cref{fig:test}

\end{document}

enter image description here

The above solution will affect all references produced by cleveref; if you want to affect just those for figure and table, use \creflabelformat

\documentclass{article}
\usepackage{cleveref}

\creflabelformat{figure}{(#2#1#3)}
\creflabelformat{table}{(#2#1#3)}

\begin{document}

\begin{table}
\centering
A
\caption{a test table}
\label{tab:test}
\end{table}
\begin{figure}
\centering
B
\caption{a test figure}
\label{fig:test}
\end{figure}

\cref{tab:test} and~\cref{fig:test}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.