# How to add combined cross-references for two subfigures?

I want to have two subfigures, and then reference them like "as seen in Figure 2a,2b" -- so to combine them.

How can I do this? (or if you know a better way in lyx or latex)

-

I slightly modified Gonzalo Medina's example in order to use the cleveref package which (among other things) automatically determines the format of a cross-reference according to its "type".

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{cleveref}

\AtBeginDocument{%
}

\begin{document}

\begin{figure}
\begin{subfigure}[b]{.5\linewidth}
\centering
\includegraphics{name1}
\caption{A subfigure}
\label{fig:one-one}
\end{subfigure}%
\begin{subfigure}[b]{.5\linewidth}
\centering
\includegraphics{name1}
\caption{A subfigure}
\label{fig:one-two}
\end{subfigure}
\caption{A figure with two subfigures}
\label{fig:one}
\end{figure}

\dots\ as seen in \Cref{fig:one-one,fig:one-two} \dots

\end{document}


EDIT: Added redefinition of \crefpairconjunction & friends.

-
(+1) Good to know. Is there a way to customize \Cref (e.g., remove the "and", or join "a,b")? Because it seems this what the OP was looking for, unless I misunderstood the question and his comment. –  chl May 26 '11 at 16:17

You can achieve what you want using the standard \ref command or \ref and \subref from the subcaption package (which should be preferred over the subfig package: subcaption vs. subfig). Here's a little example:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\begin{subfigure}[b]{.5\linewidth}
\centering
\includegraphics{name1}
\caption{A subfigure}
\label{fig:1a}
\end{subfigure}%
\begin{subfigure}[b]{.5\linewidth}
\centering
\includegraphics{name1}
\caption{A subfigure}
\label{fig:1b}
\end{subfigure}
\caption{A figure with two subfigures}
\label{fig:1}
\end{figure}

...as seen in Figures~\ref{fig:1a},\ref{fig:1b}...

...as seen in Figures~\ref{fig:1a},\ref{fig:1}\subref{fig:1b}...
\end{document}


EDIT: I added a link to the question whose answer explains why subcaption should be preferred over subfig.

-
Would you mind explaining why subcaption is better than subfig? –  chl May 26 '11 at 16:19
@chi: I've just added the link to the relevant question and its answer. –  Gonzalo Medina May 26 '11 at 20:23
Thank you (and my +1). –  chl May 28 '11 at 8:37

You can use the subfig package, and then \label each subfigure, e.g.

\documentclass{article}
\usepackage{subfig}

\begin{document}
\begin{figure}
\centering
\subfloat[This is figA]{\label{fig:figA}\Large A}\hspace{3cm}
\subfloat[This is figB]{\label{fig:figB}\Large B}
\caption{Here goes the main caption}
\label{fig:figAB}
\end{figure}

Here are Figure~\ref{fig:figA} and Figure~\ref{fig:figB}, and a combination thereof:
Figure~\ref{fig:figA},\subref*{fig:figB}.
\end{document}


Replace \Large A and \Large B with your figures.

Here is the output:

I guess you can write a simple macro to wrap up the combined call to \ref and \subref.

-
Yes, this is what I do normally. However, imagine if I cite the labels consequetively, I will have something like this: (Figure 2A FIgure 2B) with fancy formatting. What I look for is to have (Figure 2a,b) or (Figure 2a,2b). Many thanks. –  Danial Tz May 26 '11 at 9:36
@Danial Can't you just use \subref instead of \ref for referencing part B? I'll add an example. –  chl May 26 '11 at 13:04