# How to name subfigures in different figures independently

I have a problem with subfigure. I want to put some figures at different places in the section. I want to have them in pairs, so I use subfigure. But, instead of labels (a) and (b) in the Figure 1, and labels (a) and (b) in the Figure 2, I have (a) and (b) in Figure 1 and (c) and (d) in Figure 2. And it is like this in whole section. So in the end of the section, I have a pair of pictures, which I have to refer at as Figure 3(e) and 3(f). Instead of that, I would like to have each pair of pictures be named as (a) and (b). So I would have Fig. 1(a) and 1(b), Fig. 2(a) and 2(b), and so on. Do anyone know what to do with it? Thanks.

     \documentclass[12pt,a4paper]{article}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{color}
\usepackage{float}

\begin{document}

\begin{figure}[H]
\begin{subfigure}{.9\textwidth}
\centering
\includegraphics[width=.5\linewidth]{1.pdf}
\caption{$H \rightarrow b\overline{b}$}
\end{subfigure}
\begin{subfigure}{.9\textwidth}
\centering
\includegraphics[width=.5\linewidth]{2.pdf}
\caption{$H \rightarrow \gamma \gamma$}
\end{subfigure}
\caption{mmmm}
\end{figure}

text text text

\begin{figure}[H]
\begin{subfigure}{.9\textwidth}
\centering
\includegraphics[width=.5\linewidth]{1.pdf}
\caption{$H \rightarrow b\overline{b}$}
\end{subfigure}
\begin{subfigure}{.9\textwidth}
\centering
\includegraphics[width=.5\linewidth]{2.pdf}
\caption{$H \rightarrow \gamma \gamma$}
\end{subfigure}
\caption{mmmm}
\end{figure}

\end{document}

-
And how exactly are you building your subfigures? Please add to your question a simple, yet complete document allowing us to reproduce the problem mentioned. – Gonzalo Medina May 5 '13 at 22:44
@Mario S. E. I don't think so, but thank you anywhere. – Suzie May 5 '13 at 22:46
Are you embedding the first two subfigure environments in a separate figure environment from the one that includes the third and fourth subfigures? – Mico May 5 '13 at 23:16
I just see that there is a MWE now, that's fine. However I'm not able to reproduce your problem, neither with version 3.2k of the caption package bundle not with the recent version 3.3. (Furthermore I'm not aware of any version showing the problems you describe.) So Suzie, could you please add \listfiles to the very beginning of your example document and give us the output so we'll see what package versions you are actually using? – Axel Sommerfeldt May 7 '13 at 3:50
@Axel Sommerfeldt Now I have found the problem. It occurs only if I don't name both subfigures together. If I put another \caption under the second \subfigure, this problem does not occur. So I have a new question, if there is any way, that I do not need to name both subfigures together and I won't see the problem described bellow..? Thank everybody for help. – Suzie May 8 '13 at 11:33

By using the subcaption package:

\documentclass{article}

\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\begin{subfigure}[b]{.5\linewidth}
\centering
\includegraphics[scale=1]{PictureFile1}
\caption{Subfigure A}
\label{fig:labelfigure1A}
\end{subfigure}
\begin{subfigure}[b]{.5\linewidth}
\centering
\includegraphics[scale=1]{PictureFile2}
\caption{Subfigure B}
\label{fig:labelfigure1B}
\end{subfigure}
\caption{Caption of Figure 1}
\label{fig:labelfigure1}
\end{figure}

If you want to reference the subfigure A (Figure~\ref{fig:labelfigure1A}), if you want the second (Figure~\ref{fig:labelfigure1B}).  If you want to reference both (Figure~\ref{fig:labelfigure1}

For a new figure, simple add it:

\begin{figure}
\begin{subfigure}[b]{.5\linewidth}
\centering
\includegraphics[scale=1]{PictureFile3}
\caption{Subfigure A}
\label{fig:labelfigure2A}
\end{subfigure}
\begin{subfigure}[b]{.5\linewidth}
\centering
\includegraphics[scale=1]{PictureFile4}
\caption{Subfigure B}
\label{fig:labelfigure2B}
\end{subfigure}
\caption{Caption of Figure 2}
\label{fig:labelfigure1}
\end{figure}

\end{document}


UPDATE

Using your own code, this is what I have:

\documentclass[12pt,a4paper]{article}
\usepackage[english]{babel}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{color}
\usepackage{float}

\begin{document}

\begin{figure}[H]
\begin{subfigure}{.9\textwidth}
\centering
\includegraphics[width=.5\linewidth]{demo}
\caption{$H \rightarrow b\overline{b}$}
\label{fig:fig1a}
\end{subfigure}
\begin{subfigure}{.9\textwidth}
\centering
\includegraphics[width=.5\linewidth]{demo}
\caption{$H \rightarrow \gamma \gamma$}
\label{fig:fig1b}
\end{subfigure}
\caption{mmmm}
\label{fig:fig1}
\end{figure}

text text text.

Reference for Figure 1: \ref{fig:fig1}.

For Figure 1a: \ref{fig:fig1a}.

For Figure 1b: \ref{fig:fig1b}.

Reference for Figure 2: \ref{fig:fig2}.

For Figure 2a: \ref{fig:fig2a}.

For Figure 2b: \ref{fig:fig2b}.

\begin{figure}[H]
\begin{subfigure}{.9\textwidth}
\centering
\includegraphics[width=.5\linewidth]{demo}
\caption{$H \rightarrow b\overline{b}$}
\label{fig:fig2a}
\end{subfigure}
\begin{subfigure}{.9\textwidth}
\centering
\includegraphics[width=.5\linewidth]{demo}
\caption{$H \rightarrow \gamma \gamma$}
\label{fig:fig2b}
\end{subfigure}
\caption{mmmm}
\label{fig:fig2}
\end{figure}

\end{document}


Please keep in mind that [demo] was only used to replace your picture files. Just remove it on your preamble and use your files like \includegraphics[width=.5\linewidth]{yourownfilehere}.

The output of the code just mentioned is this:

-
Well, I am using that package, in fact, my code looks very similar to this one. – Suzie May 5 '13 at 22:49
@Suzie could you please provide a sample of your code to see what could be causing the problem, please? – Mario S. E. May 5 '13 at 22:53
The caption package bundle version 3.x with x <= 2 shows this behavior if the figure has no main caption since the algorithm for increasing/decreasing the sub-counter was derived from the subfig package which shows problems when using sub-figures without main caption, too. This could be solved by either using \phantomcaption (which is avail since v3.2) or updating to v3.3. – Axel Sommerfeldt May 6 '13 at 6:24