# Changing number within \numberwithin causes malfunction but no compile error

An interesting one here. It could be a bug or I might be missing a trick. In my thesis I use \numberwithin{}{} to have numbering done within sections. Top level is chapter, so it goes <chapter>.<section>.<table counter>.

In my appendix, this is too much, so I only want numbering within the chapter i.e. <chapter>.<table counter>. Therefore numbering will run across different sections and the left most digit will go up when the chapter changes.

However, if I use \numberwithin after the appendix, then it subtly messes up the numbering. It gets the number of indices correct, however, the right most index doesn't change. My guess is, that it is confused and is still thinking it should be changing the third index (which isn't printed).

I have included a working example. Any one have a clue?

\documentclass{book}
\usepackage{amsmath}

\numberwithin{table}{section}

\begin{document}
\chapter{Thing}
\section{the first section}

\begin{table}[h!]
\caption{wib}
\begin{tabular}{c}
hello
\end{tabular}
\end{table}

\begin{table}[h!]
\caption{wib}
\begin{tabular}{c}
hello
\end{tabular}
\end{table}

\section{second section}

\begin{table}[h!]
\caption{wib}
\begin{tabular}{c}
hello
\end{tabular}
\end{table}

\begin{table}[h!]
\caption{wib}
\begin{tabular}{c}
hello
\end{tabular}
\end{table}

\appendix
\numberwithin{table}{chapter}

\chapter{first appendix chapter}
\section{first appendix section}

\begin{table}[h!]
\caption{wib}
\begin{tabular}{c}
hello
\end{tabular}
\end{table}

\begin{table}[h!]
\caption{wib}
\begin{tabular}{c}
hello
\end{tabular}
\end{table}

\section{second appendix section}

\begin{table}[h!]
\caption{wib}
\begin{tabular}{c}
hello
\end{tabular}
\end{table}

\begin{table}[h!]
\caption{wib}
\begin{tabular}{c}
hello
\end{tabular}
\end{table}

\end{document}

-
Related question: how to create multilevel figure table number –  Peter Grill Sep 11 '11 at 21:04

The problem is that the counter figure is bound to section and a later \numberwithin doesn't break this binding.

\usepackage{chngcntr}
\counterwithin{figure}{section}

...

\appendix
\counterwithout{figure}{section}
\counterwithin{figure}{chapter}


While \counterwithin is quite similar to \numberwithin, amsmath lacks the ability to unbind a counter from another.

-
Seems like amsmath should change \numberwithin to handle it. Your solution works though, much appreciated. –  aghsmith Sep 11 '11 at 21:37
@aghsmith -- \numberwithin was designed to be used only in the preamble, although that isn't documented. (i just checked with the maintainer; his response: "if it works, that would be a surprise.") this matter has been posted to the amsmath requests list for reconsideration at the next overhaul. –  barbara beeton Sep 12 '11 at 20:37