# Adding parentheses around subfig references

Say I have a figure with two subfloats inserted using the subfig package. When I reference them with \ref{myLabel} I get this

Figure 3.5a and 3.5b.

But what I want is this:

Figure 3.5(a) and 3.5(b).

How can I add the parentheses?

-

For the subfig package see sections 2.2.2 and 3 of the documentation.

\documentclass{article}
\usepackage[subrefformat=parens,labelformat=parens]{subfig}

\begin{document}
\begin{figure}
\centering
\subfloat[Subfig 1]{\label{sf1} Contents of the sub-figure}
\subfloat[Subfig 2]{\label{sf2} Contents of the sub-figure}
\caption{A figure}
\label{fig}
\end{figure}
\end{document}


Assuming you're using the subfloat package, section 4 of its documentation indicates you can do something like:

\renewcommand*\thesubfloatfigure{\themainfigure(\alph{subfloatfigure})}


to put the sub-number in parentheses.

-
Unfortunately I'm using subfig. That's really my fault for leaving that unclear. –  user4600 Apr 20 '11 at 23:16
Edited for subfig. Not quite as straightforward, but easy enough. –  Mike Renfro Apr 21 '11 at 3:24
I actually found this, which works for me well: \renewcommand\thesubfigure{(\alph{subfigure})} –  user4600 Apr 21 '11 at 3:56
This also works for \usepackage[subrefformat=parens,labelformat=parens]{subcaption}. –  bkarpuz Jul 15 '13 at 8:07
\documentclass{article}
\usepackage{subfig}

\begin{document}
\begin{figure}
\centering
\subfloat[Subfig 1]{\label{sf1} Contents of the sub-figure}
\subfloat[Subfig 2]{\label{sf2} Contents of the sub-figure}
\caption{A figure}
\label{fig}
\end{figure}
\end{document}

-
It would be nice if you could say some words about your solution. We don't expect an epic story, but something like "I did ... to achieve ..." would be nice. Anyway, welcome to Tex.sX, and thanks for contributing! –  Tom Bombadil Oct 5 '11 at 23:02
@TomBombadil : I guess this is obvious as he uses '\ref' and '\subref' together. –  bkarpuz Apr 21 '13 at 16:05

If anyone came across this question and is using subcaption, here is a solution (borrowed from its excelent manual):

\documentclass{article}
\usepackage[labelformat=simple]{subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})}

\begin{document}
Reference the sub-figure in full form: \ref{sf1}.
Referencing just the sub-figure parts: \subref{sf1} and \subref{sf2}.
\begin{figure}
\begin{subfigure}{.48\textwidth}
\centering
Contents of the sub-figure
\caption{Subfig 1}
\label{sf1}
\end{subfigure}
\begin{subfigure}{.48\textwidth}
\centering
Contents of the sub-figure
\caption{Subfig 2}
\label{sf2}
\end{subfigure}
\caption{A figure}
\label{fig}
\end{figure}
\end{document}


-

The [subrefformat=parens,labelformat=parens] options didn't work for me; the references still came out as, e.g., "1b". I had to use

\usepackage[caption=false,labelformat=simple]{subfig}
\renewcommand{\thesubfigure}{(\alph{subfigure})}


(I had to use caption=false because without it subfig makes the captions in my document class come out in the wrong style.) Does this seem all right to use? I did discover that under my way, you have to use \subref*, not \subref, if you want to auto-refer to something like "(a)" (with \subref you get "((a))").

Looking at the other answer again, I think I needed to do it this way because I had been using \ref for all my references to things like "Figure 1b". (I'd rather not change all my \ref's to \subref*'s if I can avoid it.)

-