GeneralProblem with counter of subcaption and foots

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
cbustaam
Posts: 57
Joined: Mon Sep 01, 2008 10:17 pm

Problem with counter of subcaption and foots

Post by cbustaam »

Hi all,

1. I'm having some problems when I use the caption package. Example: in an float, I have the figures (a) and (b), but in the next one, I got (c) and (d) instead of again (a) and (b)... Why happens it?

2. My second problem is about the footnote counter. This start again a new chapter, but I don't soy to LaTeX that start again... Why?

This code replicates my problems:

Code: Select all

\documentclass{report}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{lipsum}
\begin{document}

\chapter{First chapter}

\lipsum[1]\footnote{Some text in the first foot}

\begin{figure}[h]
\caption{Test fig 1}
\begin{minipage}[t]{0.5\columnwidth}%
\begin{center}
\subcaption[(a)]{Fig 2a}
\end{center}

\begin{center}
\rule{4cm}{3cm}
\par\end{center}%
\end{minipage}%
\begin{minipage}[t]{0.5\columnwidth}%
\begin{center}
\subcaption{Fig2b}
\end{center}

\begin{center}
\rule{4cm}{3cm}
\end{center}
\end{minipage}
\end{figure}

\chapter{Last chapter}

\lipsum[5]\footnote{Why the counter of footer start again?!}

\begin{figure}[h]
\caption{Test fig 2}

\begin{minipage}[t]{0.5\columnwidth}
\begin{center}
\subcaption{Why start in (c) and not in (a)}
\end{center}

\begin{center}
\rule{4cm}{3cm}
\end{center}
\end{minipage}
\begin{minipage}[t]{0.5\columnwidth}
\begin{center}
\subcaption{Same problem!}
\end{center}

\begin{center}
\rule{4cm}{3cm}
\par\end{center}
\end{minipage}
\end{figure}

\end{document}
Bests
"Show me your .emacs and I'll tell you who you are." -- modified proverb

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Problem with counter of subcaption and foots

Post by gmedina »

Hi,

for the footnote counter you can use the \counterwithout command provided by the chngcntr package; add these lines to the preamble:

Code: Select all

\usepackage{chngcntr}

\counterwithout{footnote}{chapter}
For the subfigure counter, you can reset it manually; right before the second set of subfigures, add

Code: Select all

\setcounter{subfigure}{0}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
cbustaam
Posts: 57
Joined: Mon Sep 01, 2008 10:17 pm

Re: Problem with counter of subcaption and foots

Post by cbustaam »

Hi,

I guess to changing the counters manually it's possible to solve the problem, but my question goes to know what causes the problem. It will be very unpractical in a large document (as I have, with a lot of input files) check manually when a counter is doing something wrong.
So, there is a way to prevent this behaviour?

Bests
"Show me your .emacs and I'll tell you who you are." -- modified proverb
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Problem with counter of subcaption and foots

Post by gmedina »

The behaviour of the involved counters is the standard bahaviour. To change it you can use the chngcntr packages, as I suggested in my previous response. Here's a version of your code with both counters behaving as expected; notice that I used the subfigure environment provided by the subcaption package, (the reasons can be found in the documentation):

Code: Select all

\documentclass{report}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{chngcntr}
\usepackage{lipsum}

\counterwithout{footnote}{chapter}
\counterwithin{subfigure}{figure}
\renewcommand\thesubfigure{\alph{subfigure}}

\begin{document}

\chapter{First chapter}

\lipsum[1]\footnote{Some text in the first footnote}

\begin{figure}[!ht]
\centering
\caption{Test fig 1}
\begin{subfigure}[t]{0.45\columnwidth}%
  \centering
  \rule{4cm}{3cm}
  \caption{Fig 1a}
\end{subfigure}
\begin{subfigure}[t]{0.45\columnwidth}%
  \centering
  \rule{4cm}{3cm}
  \caption{Fig 1b}
\end{subfigure}
\end{figure}

\chapter{Last chapter}

\lipsum[5]\footnote{The counter continues}

\begin{figure}[!ht]
\centering
\caption{Test fig 2}
\begin{subfigure}[t]{0.45\columnwidth}%
  \centering
  \rule{4cm}{3cm}
  \caption{Fig 2a}
\end{subfigure}
\begin{subfigure}[t]{0.45\columnwidth}%
  \centering
  \rule{4cm}{3cm}
  \caption{Fig 2b}
\end{subfigure}
\end{figure}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
cbustaam
Posts: 57
Joined: Mon Sep 01, 2008 10:17 pm

Re: Problem with counter of subcaption and foots

Post by cbustaam »

Thanks a lot gmedina. The counterwithin and counterwithout commands solve the problem.

Regards.
"Show me your .emacs and I'll tell you who you are." -- modified proverb
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Problem with counter of subcaption and foots

Post by sommerfee »

cbustaam wrote:I guess to changing the counters manually it's possible to solve the problem, but my question goes to know what causes the problem.
This is a bug in the subcaption package. If there is only a single figure within a chapter, the subcaptions in the next figure (in the next chapter) will be labelled wrong.

This bug will be cleared in the next version of the caption package bundle, until then you can give the following patch a try (which should be applied after loading the subcaption package):

Code: Select all

\makeatletter
\@addtoreset{subfigure}{chapter}
\makeatother
HTH,
Axel
Post Reply