So you want to number equations by section in the main matter and by chapter in the appendix? This TeX FAQ talks about it.
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!
So you want to number equations by section in the main matter and by chapter in the appendix? This TeX FAQ talks about it.
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:
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.Code:\renewcommand{\theequation}{\thechapter.\ifnum\value{section} > 0 \arabic{section}.\fi\arabic{equation}}
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}):
Then, at the start of the Appendix, insert the command \removefromreset{equation}{section} immediately before the line \numberwithin{equation}{chapter}.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
I'd like to have something like that:
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).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)
I wrote
at the beginning of the main part and this works perfectly for the main part (it looks like the example above).Code:\numberwithin{equation}{section}
As I understand \numberwithin, a simple statement
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).Code:\numberwithin{equation}{chapter}
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!