GeneralFigure Numbers

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
tdc
Posts: 34
Joined: Fri Sep 12, 2008 1:52 am

Figure Numbers

Post by tdc »

I've been playing making an amsbook and i've included a couple of figures, however i get Figure 1 for the caption of a picture in chapter 1 and Figure 1 also for the caption of another picture in chapter 2...

how can i make it so the figure in chapter 1 is 1.1 and the figure in chapter 2 is 2.1

thanks for anyhelp :)

Tim

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

Figure Numbers

Post by gmedina »

Hi Tim,

you can use the \numberwithin command. Take a look at the following example:

Code: Select all

\documentclass{amsbook}
\numberwithin{figure}{chapter}%for figures
\numberwithin{table}{chapter}%for tables

\begin{document}

\chapter{Test chapter one}
\begin{figure}
  \centering
  \rule{5cm}{2cm}
  \caption{test figure 1.}
  \label{fig:testfig1}
\end{figure}


\chapter{Test chapter two}
\begin{figure}
  \centering
  \rule{5cm}{2cm}
  \caption{test figure 2}
  \label{fig:testfig2}
\end{figure}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Figure Numbers

Post by localghost »

The current version of the caption package has a feature that allows to set up the counter according to your wishes.

Code: Select all

\usepackage[font=small,labelfont=bf]{caption}
\captionsetup{%
  figurewithin=chapter
  tablewithin=chapter
}
Other capabilities of this package are described in its documentation.


Best regards and welcome to the board
Thorsten¹
tdc
Posts: 34
Joined: Fri Sep 12, 2008 1:52 am

Re: Figure Numbers

Post by tdc »

Ah Brill, thanks guys :)

figurewithin worked perfectly :)

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

Figure Numbers

Post by sommerfee »

localghost wrote:The current version of the caption package has a feature that allows to set up the counter according to your wishes.
Two annotations because this is not (yet) mentioned in the caption-Package manual:

1. Why is there an option "figurewithin=" in the caption package? Would not a third method of doing this be more confusing than helpful? What's the difference between \numberwithin (or \counterwithin) and the "figurewithin=" option, is there any?

Well, at first I wanted to describe \numberwithin resp. \counterwithin and their caveats in the caption package manual (you have to take care about the load and execution order when using hyperref additionally, but only it you use \numberwithin), but then I realised it would be easier for me implementing an own option (which is independent to the hyperref-load-order) than describing the so-far existing methods and their caveats. Beside that the "figurewithin=" option is independent on the load order regarding hyperref (well, at least it should be), there is a second difference: The caption package takes care about the "gap" in the List of Figure resp. List of Tables. If you use a numbering scheme bound to the chapter counter, a gap will be produced between list entry blocks from the same chapter (this is the default behaviour of most document classes), and if you unbound it from the chapter counter (e.g. with "figurewithin=none") the gap should disappear. (BTW: The "gap" is 10pt per default but you could change it by adapting the internal length \@chapterlistsgap. BTW, the 2nd: The KOMA-Script classes handles this correctly on it's own, so you won't notice this difference there.)

2. Starting from v3.1j one could also use "within=chapter" (or "within=section" or "within=none") which is valid for figure, table, and all other floating environments which will be defined with \DeclareCaptionType.

Axel
Post Reply