47

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?

5 Answers 5

31

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

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

\begin{document}
See Figure~\subref*{sf1} for more information.
\begin{figure}
\centering
\subfloat[Subfig 1]{\label{sf1} Contents of the sub-figure}
\qquad
\subfloat[Subfig 2]{\label{sf2} Contents of the sub-figure}
\caption{A figure}
\label{fig}
\end{figure}
\end{document}

Subfigures with parentheses


(Original answer)
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.

6
  • Unfortunately I'm using subfig. That's really my fault for leaving that unclear.
    – user4600
    Apr 20, 2011 at 23:16
  • Edited for subfig. Not quite as straightforward, but easy enough. Apr 21, 2011 at 3:24
  • 1
    I actually found this, which works for me well: \renewcommand\thesubfigure{(\alph{subfigure})}
    – user4600
    Apr 21, 2011 at 3:56
  • 1
    This also works for \usepackage[subrefformat=parens,labelformat=parens]{subcaption}.
    – bkarpuz
    Jul 15, 2013 at 8:07
  • 4
    \renewcommand\thesubfigure{(\alph{subfigure})} does add parentheses in citations, but also seems to cause subfloat captions to be double-parenthesized: ((a)), ((b)), etc.
    – p_a_c
    Sep 6, 2016 at 20:14
43

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}

enter image description here

3
  • 7
    For me, this caused double parenthesis before the caption of each subfigure. Adding the line: \usepackage[labelformat=simple]{subcaption}, according to this answer helped tex.stackexchange.com/questions/135358/…
    – Ross
    Jan 27, 2017 at 23:46
  • I'm getting Unknown option 'labelformat=simple' for package 'subcaption'.
    – hola
    Aug 21, 2017 at 16:06
  • 1
    This helped me. Thanks
    – Avv
    Apr 15 at 12:02
4
\documentclass{article}
\usepackage{subfig}

\begin{document}
See Figure~\ref{fig}\subref{sf1} for more information.
\begin{figure}
\centering
\subfloat[Subfig 1]{\label{sf1} Contents of the sub-figure}
\qquad
\subfloat[Subfig 2]{\label{sf2} Contents of the sub-figure}
\caption{A figure}
\label{fig}
\end{figure}
\end{document}
3
  • 7
    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! Oct 5, 2011 at 23:02
  • 1
    @TomBombadil : I guess this is obvious as he uses '\ref' and '\subref' together.
    – bkarpuz
    Apr 21, 2013 at 16:05
  • 1
    The output isn't obvious. Easy enough to try it out, though.
    – Mars
    Jan 5, 2016 at 0:17
4

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.)

1

Combining ideas from some of the other answers, this is what works best for me:

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

The line with \renewcommand now makes \ref work as I want, namely 1(a), so there is no need to use \subref* as in other solutions above.

This has now added double brackets in various places, which have to be removed. \labelformat=simple removes them from the subfigures, so these are now displayed as (a).

\listofformat=subsimple removes the double brackets from \listoffigures (which is only visible with \setcounter{lofdepth}{2}) and from \subref. So now I can use \subref if I just want (a).

caption=false is used because caption is incompatible with revtex, which is my class file, but shouldn't have any impact on the problem at hand.

1
  • Thanks for editing my reply to improve the formatting. I am new to this :) Feb 27, 2020 at 10:48

You must log in to answer this question.