Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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)

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

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{%
  \renewcommand{\crefpairconjunction}{,}%% instead of " and\nobreakspace"
  \renewcommand{\crefmiddleconjunction}{,}% instead of ", "
  \renewcommand{\creflastconjunction}{,}% instead of " and\nobreakspace"
}

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

enter image description here

share|improve this answer
    
(+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
add comment

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.

share|improve this answer
    
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
add comment

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:

enter image description here

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

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.