[Tex/LaTex] Do section counters need to be reset if you reset chapter counter

countersnumberingtable of contents

The answer to this question How to remove chapter numbering without removing it from tableofcontents was given as:

\newcommand{\mychapter}[2]{
    \setcounter{chapter}{#1}
    \setcounter{section}{0}
    \chapter*{#2}
    \addcontentsline{toc}{chapter}{#2}
}

I don't have enough reputation to comment on posts yet so I wanted to ask what is the use of resetting the \setcounter{section}{0} counter line. I am trying to learn LaTeX in a bit more depth so would appreciate if someone could explain what they do. commenting them out of my preamble doesnt seem to make any difference. Does the section counter not refer to the count of the chapter before it and therefore if you've changed that counter it will change automatically?

Best Answer

The user answering (How to remove chapter numbering without removing it from tableofcontents) the linked question wants to remove the chapter numbers there, but keep the section numbering 'consistent'.

This can be achieved in the way the user did: Use \chapter* to prevent the chapter counter to be displayed, however, this does not increase or set the chapter counter.

Section counters are (usually) defined via \newcounter{section}[chapter], so each time they are reset, when \refstepcounter{chapter} or \stepcounter comes in action, which is not the case when \chapter*{}is applied (for \chapter it's done so). (\refstepcounter is the labelling-counter-step, calling \stepcounter, which is in turn some special version of \addtocounter{countername}{1}.)

The answerer had to manually set \setcounter{section}{0} in this case, each time \mychapter is used to achieve the specific needs of the OP of the linked question. This way the section numbers are consistent and reset each time if such a specific fake chapter is used

The order of usual hierarchy: (without \part)

  1. Chapter counter get's \stepcountered or \refstepcountered.
  2. Since \newcounter{section}[chapter] was used, this the previous step triggers the resetting of the section counter. The section counter does not depend on a special chapter counter value, it's just the increasing step.

The answer to the question is here: In general, section counters do not require to be reset if not explictly defined, but in the linked question, the section numbering should be consistent and with the method applied in the linked answer, this \setcounter{section}{0} is just one way to do so.

If one bypasses the automatic resetting, one has to pay ;-)

Related Question