Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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