6

When I create a table and use \caption, Latex automatically adds "Table 1.1" or something similarly numbered. I'm using the book format, and want the caption numbering to be of the form "Table x.y.z", where x is the chapter number, y is the section number, and z is the table number within x.y. For example, the second table in section 4 in chapter 2 should say "Table 2.4.2".
How do I make Latex change the numbering of the tables?

1

2 Answers 2

11

Although your question is closely related to the following question, the numbering scheme you want is different.

The general solution is the same, however:

Use the chngcntr package to determine which counters depend on which. In your case, you want the table counter to depend on the section counter, so you add

\usepackage{chngcntr}
\counterwithin{table}{section}
3
  • 1
    bit of a shame that Peter invented a new name for this and did not use the amsmath name that is around for ages Commented Apr 1, 2012 at 4:57
  • @FrankMittelbach I guess if he used the same name, the package might clash with amsmath. This way there's no conflict (even though it wouldn't be needed). I don't know if that was the reasoning.
    – Alan Munn
    Commented Apr 1, 2012 at 5:08
  • I was thinking about that but in this particular case it doesn't really make much sense as he could have just "provided" the definition ... well it is the way it is by now. Commented Apr 1, 2012 at 5:29
9

For this two things are needed:

  1. the table counter need resetting whenever the section counter is stepped
  2. the command to display the counter value should show the combination of chapter, section and table.

You achieve the first by placing

\makeatletter
\@addtoreset{table}{section}
\makeatother

into the preamble of your document. The second step is done through

\renewcommand\thetable{\thesection.\arabic{table}}

where \thesection is the "display number" of the current section which in book is equiv to \arabic{chapter}.\arabic{section}.

When using amsmath

If you use the amsmath package the solution is even simpler as this packages offers a declaration that combines the above steps:

\numberwithin{table}{section}
2
  • I like this solution over using another package because it allows you to modify the appearance, for example if someone wanted to us a dash or other separator, \thesection-\arabic{section} Commented Jan 18, 2014 at 3:55
  • this solution seems to destroy the \listoftables as there are the numbers now written in the caption of the table
    – user69453
    Commented Jul 5, 2016 at 10:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .