3

I have a lot of files including images and I want them to be numbered continuously.

I use many images next to each other, which looks like

\begin{figure}[H]
    \begin{subfigure}[t]{0.45\textwidth}
            \includegraphics[bla]{bla1.jpg}
            \caption{bla}
            \label{fig:bla1}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
        \includegraphics[bla]{bla2.jpg}
            \caption{bla}
            \label{fig:bla2}
    \end{subfigure}
\end{figure}

Their caption labels are (1) and (2).

Then I have single images like:

\begin{figure}[H]
\begin{subfigure}{0.62\textwidth}
    \includegraphics[bla]{bla3.jpg}
    \caption{bla}
    \label{fig:bla3}
\end{subfigure}
\end{figure}

Its label is (1) again, but I would like it to have (3).

My attempt was to use:

\usepackage{chngcntr}
\counterwithout{subfigure}{figure}

so that it ignores the figure-environment. It does not work.

The problem is that I am using memoir as documentclass, without using chapters. Originally, the pictures were numbered continuously like 0.1, 0.2, 0.3 etc., because they were in minipages instead of subfigures. But I wanted to remove the 0, so that I replaced the minipages with subfigures and

\renewcommand{\thesubfigure}{\arabic{subfigure}}

I hope this is understandable and I appreciate your help!

  • What about DCs 'remreset'? – Ruben Sep 21 '13 at 14:09
  • What about \ContinuedFloat? – Axel Sommerfeldt Sep 22 '13 at 7:46
3

Here is my solution using the etoolbox package and a new counter which will be increased by one each time the subfigure environment is called.

\documentclass{memoir}

\usepackage[draft]{graphicx}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{etoolbox}
\newcounter{fignumber}
\setcounter{fignumber}{0}

\renewcommand{\thesubfigure}{\arabic{fignumber}}

\AtBeginEnvironment{subfigure}{\refstepcounter{fignumber}}

\begin{document}

\begin{figure}[H]
    \begin{subfigure}[t]{0.45\textwidth}
            \includegraphics{bla1.jpg}
            \caption{bla}
            \label{fig:bla1}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
        \includegraphics{bla2.jpg}
            \caption{bla}
            \label{fig:bla2}
    \end{subfigure}
\end{figure}

\begin{figure}[H]
\begin{subfigure}{0.62\textwidth}
    \includegraphics{bla3.jpg}
    \caption{bla}
    \label{fig:bla3}
\end{subfigure}
\end{figure}

\end{document}

EDIT It turned out that the above solution is not entirely satisfying when calling \ref{} with one of the labels defined (see this question). In order to fix that, just add these lines to your preamble:

\makeatletter
\renewcommand{\p@subfigure}{}
\makeatother

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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