5

Using pretty much no packages, when using the \ref{label of figure} i get just the number of the figure. Is there an easy way to set it to make parentheses around that number? At the moment I have to do it manually, but would be nicer if it could be done automatically

  • 3
    Are you comfortable with that happening for all references? Including those to a table, a section, an equation, ... – Werner Mar 17 '14 at 21:05
  • Welcome to TeX.SE! You could create a little macro, say \newcommand\pref[1]{(\ref{#1})} -- short for "parenthetical \ref", I suppose -- and place it in the preamble. Then, write \pref{<label of figure>}. The point is that by creating the macro \pref you need not modify the default behavior of \ref. – Mico Mar 17 '14 at 21:08
4

You can use the \p@figure macro that's used in building the current label.

\documentclass{article}
\makeatletter
\renewcommand\p@figure{\expandafter\counter@parenthesize}
\newcommand\counter@parenthesize[1]{(#1)}
\makeatother

\begin{document}

\begin{figure}
\caption{X}\label{X}
\end{figure}

See Figure~\ref{X}.

\end{document}

enter image description here

You can do similarly for the other counters you need to be treated in a similar way.

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.