2013年10月27日星期日

Counter Numbering Configuration in LaTeX

When using some template to write our documents, especially those classical and well-structured ones, such as PhD Thesis, we might run into some undesirable features bound to that template. For instance, the counter of footnote is reset for each page, namely if you have 10 footnotes created by the standard "\footnote" commands all over your document, but they are distributed on 10 different pages, then the numberings will all be "1", instead of "1", "2",...,"10". This also happens for linguistic examples created by the "linguex" package, whose counter will be reset for every chapter.

In LaTeX, the objects coming with an automatic numbering, such as tables, figures, footnotes, etc., contain an internal counter definition:

  1. \newcounter{counter_name}
  2. \newcounter{counter_name}[resetting_environment]
The second differs from the first by adding a resetting environment, which appears as once the environment changes, the counter will be reset to 0. That is why some counters are continuous across the whole document, while some others are reset at certain point.


Since the initialization of the counter is embedded in the definition of each object, which is really difficult to modify directly, so in order to be completely flexible on configuring the numbering, we can use the "chngcntr" package. There are basically a pair of commands that we can use:

  • \counterwithin{1}{2} or \counterwithin*{1}{2}
    • These commands help to add a resetting environment to a counter without it
    • The first compulsory argument denotes the counter name, for instance "footnote" for footnotes, "table" for tables, "ExNo" for linguistic examples, etc.
    • The second compulsory argument denotes the environment within which you want to reset the counter, for instance, "chapter", "section", etc.
  • \counterwithout{1}{2} or \counterwithout*{1}{2}
    • These commands help to eliminate a resetting environment for a counter under its influence
    • Same as above, the first compulsory argument denotes the counter name
    • Same as above, the second compulsory argument denotes the environment within which you want to eliminate the resetting effect for a counter

The starred version, "\counterwithin*" or "\counterwithout*" will suppress the redefinition of another counter-related command "\the{counter_name}", for more details, please look at the reference.




Reference:

http://mirrors.linsrv.net/tex-archive/macros/latex/contrib/chngcntr/chngcntr.pdf
http://en.wikibooks.org/wiki/LaTeX/Counters

没有评论:

发表评论