I don't think using three different formats for the numbering of subfigures is good. Anyway, here it is:
\documentclass{article}
\usepackage{caption}
\captionsetup[figure]{labelsep=period,justification=centering,singlelinecheck=off}
\DeclareCaptionLabelFormat{rightparen}{#2)}
\usepackage{subfig}
\captionsetup[subfloat]{labelformat=rightparen}
\showcaptionsetup[uniq]{subfloat}
\usepackage{xparse}
\ExplSyntaxOn
\seq_new:N \g_akj_subfloat_seq
\NewDocumentCommand{\xsubfloat}{ m m }
{
\akj_subfloat:nn { #1 } { #2 }
}
\NewDocumentCommand{\makexcaption}{o}
{
\caption{\IfNoValueF{#1}{#1~}Subfigures:~%
\seq_use:Nnnn \g_akj_subfloat_seq {;~} {;~} {;~}}
}
\cs_new_protected:Npn \akj_subfloat:nn #1 #2
{
% initialize
\int_compare:nT { \value{subfigure} = 0 }
{ \seq_gclear:N \g_akj_subfloat_seq }
% do the subfloat
\subfloat[]{#2}
% store the subcaption
\seq_gput_right:Nx \g_akj_subfloat_seq { (\exp_not:N\textit{\alph{subfigure}}) ~ \exp_not:n { #1 } }
}
\ExplSyntaxOff
\renewcommand{\thesubfigure}{\textit{\alph{subfigure}}}
\makeatletter
\def\p@subfigure{\thefigure\,}
\makeatother
\begin{document}
\begin{figure}
\centering
\xsubfloat{subfigure A}{%
\rule{100pt}{50pt}%
\label{fig:subfig-a}%
}
\xsubfloat{subfigure B}{%
\rule{100pt}{50pt}%
\label{fig:subfig-b}%
}
\xsubfloat{subfigure C}{%
\rule{100pt}{50pt}%
\label{fig:subfig-c}%
}
\makexcaption\label{fig:figures}
\end{figure}
See Figures~\ref{fig:subfig-a}, \ref{fig:subfig-b} and~\ref{fig:subfig-c}.
\end{document}
The \makexcaption
command has also an optional argument for text going before the list of subcaptions, so
\makexcaption[Some text.]
would produce
Figure 1. Some text. Subfigures: (a) subfigure A; (b) subfigure B; (c) subfigure C
Beware of unprotected end-of-lines in the arguments of \subfloat
, that are the cause of your spurious spaces.
subfigure
is an obsolete package which shouldn't be used anynore. In its stead you can use subfig
or subcaption
. Below, I used the former, since subcaption
will produce a warning about revtex4-1
being unsupported by caption
(this might not be an issue, but I am not sure):
Notice the line
\captionsetup[subfigure]{labelformat=brace}
so the caption number will have only one parenthesis (instead of the default formatting enclosing the number inside parentheses).
\documentclass[10pt,prl,aps,showpacs,twocolumn,unsortedaddress]{revtex4-1}
\usepackage[caption=false]{subfig}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{commath}
\usepackage{graphicx,bm}
\usepackage{verbatim}
\captionsetup[subfigure]{labelformat=brace}
\begin{document}
\begin{figure*}
\subfloat[text for the first subfigure\label{sfig:testa}]{%
\includegraphics[height=3cm,width=.49\linewidth]{example-image-a}%
}\hfill
\subfloat[text for the second subfigure\label{sfig:testa}]{%
\includegraphics[height=3cm,width=.49\linewidth]{example-image-b}%
}
\caption{}
\label{}
\end{figure*}
\end{document}
With subcaption
, the code would be:
\documentclass[10pt,prl,aps,showpacs,twocolumn,unsortedaddress]{revtex4-1}
\usepackage{subcaption}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{commath}
\usepackage{graphicx,bm}
\usepackage{verbatim}
\captionsetup[subfigure]{labelformat=brace}
\begin{document}
\begin{figure*}
\begin{subfigure}{0.49\linewidth}
\centering
\includegraphics[height=3cm,width=\linewidth]{example-image-a}
\caption{text for the first subfigure}
\label{sfig:testa}
\end{subfigure}\hfill
\begin{subfigure}{0.49\linewidth}
\centering
\includegraphics[height=3cm,width=\linewidth]{example-image-b}
\caption{test for the second subfigure}
\label{sfig:testb}
\end{subfigure}\hfill
\caption{}
\label{}
\end{figure*}
\end{document}
But, as I mentioned before, you'll receive a warning:
Package caption Warning: Unsupported document class (or package)
detected, usage of the caption package is not recommended.See the
caption package documentation for explanation.
Best Answer
Here is a solution with
subcaption
. I think similar result can be obtained by usingsubfloat
also.Just give
\caption{}
without any arguments so that it will print only the label ((a),(b)...) not the caption text. And then caption can be given for main figure, where subfigures can be 'sub'-reffered. Sample output:Corresponding MWE made by modifying code from another question.
EDIT
The caption can be placed on the left side by manually putting it there and using
\phantomsubcaption
to suppress the automatic caption. Sample output:The corresponding code: