# Math Help - scrbook & amsmath: wrong equation numbering in appendix

1. ## scrbook & amsmath: wrong equation numbering in appendix

Hi everybody,

I'm facing a curious problem: Using "\numberwithin{equation}{section}", equation numbering starts at "1" in each new section ((1.1.1), (1.1.2), (1.2.1), ...) and that's fine. In the appendix, however, I switch to "\numberwithin{equation}{chapter}" and expect a numbering ((A.1), (A.2), (B.1), (B.2), ...). This indeed works as long as I refrain from adding sections in the appendix: a new \section in an appendix-chapter (labeled by "A") leads to ambiguous numbering: ((A.1), (A.2), "\section", (A.1), (A.2), (B.1), (B.2), ...).

Strangely, changing "\numberwithin{equation}{section}" to "\numberwithin{equation}{chapter}" leads to correct numbering in the appendix. But I'd like to have sectionwise-numbering in the mainmatter.

How do get \numberwithin to work properly?

A 'next-to-minimum' example is attached.

Thanks for helping!

2. So you want to number equations by section in the main matter and by chapter in the appendix? This TeX FAQ talks about it.

3. If I understand this correctly, you want the equation numbers at the start of the Appendix to look like (A.1), (A.2), ... . Then when a Section of the Appendix starts, you want the numbering to look like (A.1.1), (A.1.2), ... .

If that is indeed what you want, you cannot get it by simple \numberwithin commands. What you need to do is to replace the command \numberwithin{equation}{chapter} (just after the \appendix line) with this:

Code:
\renewcommand{\theequation}{\thechapter.\ifnum\value{section} > 0 \arabic{section}.\fi\arabic{equation}}
That way, you will get an output with three components (A.x.y), except that the middle component (the section number) will be suppressed if it is equal to 0.

Edit. On the other hand, if you want the equation numbers in the Appendix to have just two components, of the form (A.x), regardless of whether there are Sections or not, you need to install a \removefromreset command. Insert this code in the preamble of your file (just before \begin{document}):

Code:
\makeatletter
\def\removefromreset#1#2{{%
\expandafter\let\csname c@#1\endcsname\removefromreset
\def\@elt##1{%
\expandafter\ifx\csname c@##1\endcsname\removefromreset
\else
\noexpand\@elt{##1}%
\fi}%
\expandafter\xdef\csname cl@#2\endcsname{%
\csname cl@#2\endcsname}}}
\makeatother
Then, at the start of the Appendix, insert the command \removefromreset{equation}{section} immediately before the line \numberwithin{equation}{chapter}.

4. I'd like to have something like that:

Code:
CHAPTER ONE:
Section one
eq(1.1.1)
eq(1.1.2)
Section two
eq(1.2.1)
eq(1.2.2)
APPENDIX CHAPTER ONE
eq(A.1)
appendix section one
eq(A.2)*
eq(A.3)
appendix section two
eq(A.4)*
eq(A.5)
So within the main part, the section number is used for numbering equations and numbering restarts each section. But in the appendix I don't need the section number for equation numbering. And most importantly, equation numbering should NOT restart each new section. But this is what happens: every numer marked with a asterisk is labeled (A.1).

I wrote
Code:
\numberwithin{equation}{section}
at the beginning of the main part and this works perfectly for the main part (it looks like the example above).

As I understand \numberwithin, a simple statement
Code:
\numberwithin{equation}{chapter}
at the beginning of the appendix ought to do the trick (restart numbering each chapter, no section number for numbering equations), but somehow it doesn't work (no section number for numbering equations is ok, but numbering still restarts each section).

I hope this clearifies my problem. So, what's wrong with \numberwithin? I'd like to understand why LaTeX does what it does and how to fix this straightforward (without workarounds). At least if possible.

Thanks again!

5. In my experiment, saying

\counterwithout{equation}{section}
\counterwithin{equation}{chapter}

inside the appendix produces the result you want.

6. You're right emakarov, it works. Thanks for your quick responses!

Yet, is this a bug in numberwithin? Doesn't the "chapter" in \numberwithin{equation}{chapter} state that numbering is reset each "chapter"?