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?
Asked
Active
Viewed 3.8k times
6
Christopher Aden
- 285
2 Answers
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}
-
1bit of a shame that Peter invented a new name for this and did not use the amsmath name that is around for ages – Frank Mittelbach Apr 01 '12 at 04: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 Apr 01 '12 at 05: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. – Frank Mittelbach Apr 01 '12 at 05:29
9
For this two things are needed:
- the
tablecounter need resetting whenever thesectioncounter is stepped - 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}
SimplyKnownAsG
- 249
Frank Mittelbach
- 77,146
-
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}– SimplyKnownAsG Jan 18 '14 at 03:55 -
this solution seems to destroy the
\listoftablesas there are the numbers now written in the caption of the table – user69453 Jul 05 '16 at 10:58
chngcntrpackage, plus\counterwithin{table}{section}. See this question Continuous v. per-chapter/section numbering of figures, tables, and other document elements for more details. – Alan Munn Apr 01 '12 at 04:28