Generalsubfigure numbering using figurewithin in caption package

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
trashus
Posts: 3
Joined: Mon Sep 29, 2008 10:07 pm

subfigure numbering using figurewithin in caption package

Post by trashus »

I am trying to use the caption and subcaption packages to label subfigures, and I am having problems with the numbering (perhaps I should say "lettering") of the subfigures when I use the figurewithin=section option.

When I load the caption packages this way:

Code: Select all

\usepackage[font=small,labelfont={bf,sl},textfont=sl,labelsep=colon,justification=centering]{caption}
everything works fine and the subfigures are labeled 1a, 1b, 2a, 2b.

However, I would like to have equation numbers that go by section, so I load the caption package as above, except with the additional option figurewithin=section. The problem is that the subfigures end up being labeled 1.1a, 1.1b, 2.1c, 2.1d, instead of 1.1a, 1.1b, 2.1a, 2.1b. It seems the subequation counter is not starting over at the end of a section (as though the subfigure environment didn't get closed?).

Also, I noticed that adding another figure (without a subfigure) in the first section doesn't help, but that adding another figure (with a subfigure) in the first section fixes the problem. That is, it gives the correct numbering for the figure in the second section (i.e. 2.1a, 2.1b instead of 2.1c, 2.1d), and it gives the correct numbering for the added figure in the first section (i.e. 1.2a).

Does anyone know what's going on or how to fix it? What can I do to ensure that subfigure counters start over in each section, regardless of how many subfigures are in the previous section?

I have attached a .tex file that illustrates the problem. Make sure to compile twice to get labels right.

[EDIT] Oh, and here is the .jpg needed to compile the .tex file.
Attachments
test_tables.jpg
test_tables.jpg (1.02 KiB) Viewed 4098 times
figurewithin.tex
(3.96 KiB) Downloaded 353 times

Recommended reading 2024:

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

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

sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

subfigure numbering using figurewithin in caption package

Post by sommerfee »

trashus wrote: Does anyone know what's going on or how to fix it? What can I do to ensure that subfigure counters start over in each section, regardless of how many subfigures are in the previous section?
This is a bug in the caption package which will be fixed in the next version (which hopefully will be released at the end of this month).

Until then, the following lines after \usepackage[...]{subcaption} should fix the problem right now:

Code: Select all

\makeatletter
\@addtoreset{subfigure}{section}
\makeatother
Axel
Post Reply