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?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityFor 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}
(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.
\usepackage[subrefformat=parens,labelformat=parens]{subcaption}
.
\renewcommand\thesubfigure{(\alph{subfigure})}
does add parentheses in citations, but also seems to cause subfloat captions to be double-parenthesized: ((a)), ((b)), etc.
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}
\usepackage[labelformat=simple]{subcaption}
, according to this answer helped tex.stackexchange.com/questions/135358/…
Unknown option 'labelformat=simple' for package 'subcaption'.
\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}
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.)
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.