1

This question already has an answer here:

Why does the caption start with number 2 and how to fix it?

\documentclass{article}

\usepackage{mwe}
\usepackage{subcaption}

\begin{document}

\begin{center}
\captionsetup{type=figure}
\begin{subfigure}{0.4\textwidth}
\includegraphics[width=\textwidth]{example-image-a.pdf}
\end{subfigure}
\begin{subfigure}{0.4\textwidth}
\includegraphics[width=\textwidth]{example-image-b.pdf}
\end{subfigure}
\captionof{figure}{Description}
\end{center}
\end{document}

Output: enter image description here

Maybe also see here

marked as duplicate by Johannes_B, Salim Bou, Mico, Seamus, Mensch Sep 4 '16 at 14:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • hy are you posting the same question twice? It is pretty much very very lickely that solving one mystery will automatically get rid of the other one. – Johannes_B Sep 4 '16 at 13:02
  • Argh, now i voted on the wrong one to close. – Johannes_B Sep 4 '16 at 13:02
  • I actually don't know if it's related. But I can produce both "errors" without the other – Ben Sep 4 '16 at 13:14
  • 3
    Unfortunately this question was already closed so I cannot answer. So I will do so within this comment: Just change \captionof{figure}{...} to \caption{...} and the counting will be fine. Background: With \captionsetup{type=figure} you say "Hey, here starts some kind of figure, so increase the figure counter etc.". And with \captionof{figure}{...} you say "Hey, this isn't a figure but typeset the caption like a figure caption and btw please increase the figure counter". So it gets incremented twice. – Axel Sommerfeldt Sep 4 '16 at 14:14
  • 1
    @cfr Yes. When using the caption package \captionof{figure}{...} is only a abbreviation of \captionsetup{type=figure}\caption{...}. – Axel Sommerfeldt Jun 15 '18 at 8:29
3

Use the H placement of a figure environment, or add this as a workaround: \addtocounter{figure}{-1}:

\documentclass{article}

\usepackage{mwe}
\usepackage{subcaption,float}

\begin{document}

\begin{figure}[H]
  \centering
  \begin{subfigure}{0.4\textwidth}
    \includegraphics[width=\textwidth]{example-image-a.pdf}
  \end{subfigure}
  \qquad
  \begin{subfigure}{0.4\textwidth}
    \includegraphics[width=\textwidth]{example-image-b.pdf}
  \end{subfigure}
  \caption{Description}
\end{figure}

\begin{center}
\captionsetup{type=figure}\addtocounter{figure}{-1}
    \begin{subfigure}{0.4\textwidth}
    \includegraphics[width=\textwidth]{example-image-a.pdf}
    \end{subfigure}
    \qquad
    \begin{subfigure}{0.4\textwidth}
    \includegraphics[width=\textwidth]{example-image-b.pdf}
    \end{subfigure}
\captionof{figure}{Description}
\end{center}
\end{document} 

enter image description here

  • 1
    Because I don't want that my images float – Ben Sep 4 '16 at 13:21
  • OK. Please see my updated answer if it solves your problem. – Bernard Sep 4 '16 at 13:37
  • I heard, that H actually doesn't mean here to 100%, so I'm still avoiding it. I got a solution here which uses minipages, which solves this problem too – Ben Sep 4 '16 at 14:20
  • It really means here (as far as I know), but this implies a drawback: you may have unwanted whitespace if the image has to go to next page. In my opinion, it is wiser to let LaTeX decide first, and in a second time use the H joker if you think it's not the right choice. – Bernard Sep 4 '16 at 15:05
  • I definitely want the images to show up, where I place them – Ben Sep 4 '16 at 15:12

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