1

I'm not fully understanding how chngcntr works. I've attached an example that hopefully explains my confusion, along with the source code, of course.

What I want is for the first section to be numbered as 1.1, 1.2,... the second as 2.1.1, 2.1.2, 2.2.1, 2.2.2,... and then the third back to 3.1, 3.2, ....

\documentclass[]{article}
\usepackage{chngcntr}
\newtheorem{thm}{Theorem}[section]
\begin{document}

\section{Labels 1.1, 1.2, ...}
\begin{thm} Theorem 1 \end{thm}
\subsection{New Subsection \textit{Does Not} Change Counter}
\begin{thm} Theorem 2 \end{thm}
\subsection{And Again}
\begin{thm} Theorem 3 \end{thm}

------------------------------

\section{Labels 1.1.1, 1.1.2, 1.2.1, ...}
\counterwithin{thm}{subsection}
\subsection{Subsection}
\begin{thm} Theorem 1 \end{thm}
\begin{thm} Theorem 2 \end{thm}
\subsection{New Subsection \textit{Does} Change Counter}
\begin{thm} Theorem 3 \end{thm}
\begin{thm} Theorem 4 \end{thm}

------------------------------

\section{Now I Try to Go Back to the First Case...}
\counterwithin{thm}{section}
\subsection{Subsection 1}
\begin{thm} Theorem 1 \end{thm}
\subsection{Subsection 2 -- Counter Is Reset to the Start}
\begin{thm} Theorem 2 \end{thm}

\end{document}

Display

2

1 Answer 1

1

Apart from the non-recommended numbering scheme...

\newtheorem{thm}{Theorem}[section] subjects the thm counter to being reset by section.

Now, \counterwithin{thm}{subsection} sets thm on the reset list of subsection too. This is 'ok' as long as \subsection is used.

Switching back with

\counterwithin{thm}{section}

is not sufficient later on, since thm is still on the reset list of subsection, so any unstarred \subsection command will reset the thm counter. This is wrong and not requested, so the thm counter must be removed from the reset list first:

\counterwithout{thm}{subsection}
\counterwithin{thm}{section}

to revert the numbering and resetting.

\documentclass[]{article}
\usepackage{chngcntr}
\newtheorem{thm}{Theorem}[section]

\begin{document}

\section{Labels 1.1, 1.2, ...}
\begin{thm} Theorem 1 \end{thm}
\subsection{New Subsection \textit{Does Not} Change Counter}
\begin{thm} Theorem 2 \end{thm}
\subsection{And Again}
\begin{thm} Theorem 3 \end{thm}

------------------------------

\section{Labels 1.1.1, 1.1.2, 1.2.1, ...}
\counterwithin{thm}{subsection}
\subsection{Subsection}
\begin{thm} Theorem 1 \end{thm}
\begin{thm} Theorem 2 \end{thm}
\subsection{New Subsection \textit{Does} Change Counter}
\begin{thm} Theorem 3 \end{thm}
\begin{thm} Theorem 4 \end{thm}

------------------------------

\section{Now I Try to Go Back to the First Case...}
\counterwithout{thm}{subsection}
\counterwithin{thm}{section}
\subsection{Subsection 1}
\begin{thm} Theorem 1 \end{thm}
\subsection{Subsection 2 -- Counter Is Reset to the Start}
\begin{thm} Theorem 2 \end{thm}

\end{document}

enter image description here

8
  • Ah, I see: the suffix -in/-out works a bit like a start/stop? That is the bit that I wasn't understanding (the documentation didn't make this clear to me).
    – Sam OT
    Commented Oct 16, 2017 at 15:14
  • @SamT: start/stop is the wrong term. Push and pull is better ;-) And the documentation is pretty clear, in my point of view
    – user31729
    Commented Oct 16, 2017 at 15:18
  • I don't know what push/pull would mean in this sense =P -- once you've explained it, I can see what the documentation means. However, you have 125k rep on here, and I have 67 (plus association bonus), so it's to be expected that you understand it better than me! =P
    – Sam OT
    Commented Oct 16, 2017 at 15:20
  • @SamT: \counterwithinpush the counter on the reset list, \counterwithoutpull the counter from the reset list
    – user31729
    Commented Oct 16, 2017 at 15:21
  • Ah, I see. Thanks very much, that's very helpful! :)
    – Sam OT
    Commented Oct 16, 2017 at 15:23

You must log in to answer this question.

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