# Numbering equations within chapters without using the chapter number [closed]

Unfortunately, I'm running into the same problem for a couple of times now. I can't find the answer anywhere on this forum, so that is why I decided to post the question. What I am trying to do right now is to number the equations, but once I go to a new chapter (without using the "Chapter 1/2/3" title) I want the number of the equations to start again.

Hence, I want:

Chapter 1

Section 1

x (1.1.1)

y (1.1.2)

Section 2 z (1.2.1) g (1.2.2)

Chapter 2

Section 1

r (2.1.1)

Unfortunately, when I use the numbered equations in chapter 2, I get (2.4.1) and not (2.1.1.)

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{longtable}
\usepackage{graphicx}
\usepackage{fullpage}

\title{Equations in chapters}

\author{Student NL}

\begin{document}

\maketitle
\chapter*{Problem 1}

\section*{Question 1}

\begin{subequations}
\renewcommand{\theequation}{\theparentequation.\arabic{equation}}
$$X = 8$$

$$y = 9$$
\end{subequations}

\section*{Question 2}
\begin{subequations}
\renewcommand{\theequation}{\theparentequation.\arabic{equation}}
$$A = 3$$

$$B = 5$$
\end{subequations}

\chapter*{Problem 2}

\section*{Question 1}

\begin{subequations}
\renewcommand{\theequation}{\theparentequation.\arabic{equation}}
$$C = 5$$

$$D = 0$$
\end{subequations}

\section*{Question 2}
\begin{subequations}
\renewcommand{\theequation}{\theparentequation.\arabic{equation}}
$$E = 1$$

$$F = 6$$
\end{subequations}

\end{document}


How can I change this?

Suppose now, as some of you suggested, I make use of the Chapter numbers. I do have another issue then. In the example below, in chapter 2, section 2 does not contain any equations, while section 3 does. In section 3, I then get 2.2.1 instead of 2.3.1. How can I avoid this?

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{longtable}
\usepackage{graphicx}
\usepackage{fullpage}

\title{Equations in chapters}

\author{Student NL}

\begin{document}

\maketitle
\chapter{Problem 1}

\section{Question 1}

\begin{subequations}
\renewcommand{\theequation}{\theparentequation.\arabic{equation}}
$$X = 8$$

$$y = 9$$
\end{subequations}

\section{Question 2}
\begin{subequations}
\renewcommand{\theequation}{\theparentequation.\arabic{equation}}
$$A = 3$$

$$B = 5$$
\end{subequations}

\chapter{Problem 2}

\section{Question 1}

\begin{subequations}
\renewcommand{\theequation}{\theparentequation.\arabic{equation}}
$$C = 5$$

$$D = 0$$
\end{subequations}

\section{Question 2}
\section{Question 3}
\begin{subequations}
\renewcommand{\theequation}{\theparentequation.\arabic{equation}}
$$E = 1$$

$$F = 6$$
\end{subequations}

\end{document}


## closed as unclear what you're asking by user31729, Maarten Dhondt, Henri Menke, darthbith, Martin SchröderMay 23 '16 at 13:58

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• it is more or less impossible to guess what your input looks like and why the equation number is not being reset, try to make a small self contained document that shows the problem and add it to your question. – David Carlisle Jan 31 '16 at 11:56
• \chapter*{Problem 2} \section*{Question 1} \begin{subequations} \renewcommand{\theequation}{\theparentequation.\arabic{equation}} $$C = 5$$ $$D = 0$$ \end{subequations} \end{document} – Student NL Jan 31 '16 at 12:30
• This is what I wrote in LaTeX – Student NL Jan 31 '16 at 12:30

It seems that you just want equations numbered per section rather than per chapter

\numberwithin{equation}{section}


\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{longtable}
\usepackage{graphicx}

\numberwithin{equation}{section}

\title{Equations in chapters}

\author{Student NL}

\begin{document}

\maketitle
\chapter{Problem 1}

\section{Question 1}

aaa
$$X = 8$$

aaa
$$y = 9$$

\section{Question 2}
aaa
$$A = 3$$
aaa
$$B = 5$$

\chapter{Problem 2}

\section{Question 1}
aaa
$$C = 5$$
aaa
$$D = 0$$

\section{Question 2}
\section{Question 3}
aaa
$$E = 1$$
aa
$$F = 6$$

\end{document}

• Voting up, since nobody else appreciates your answer ;-) – user31729 Feb 2 '16 at 21:09

Note: The O.P. changed the question to another direction, but this was answered before those changes.

As far as I understand the O.P. the trouble is that \chapter* does not reset the equation counter (as no other counter is reset as well). This can be cured by using \xpretocmd.

The counter output format should be changed as a patch too, since subequations redefines this everytime it's called.

\documentclass{report}

\usepackage{xpatch}

\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\xpatchcmd{\subequations}{%
\def\theequation{\theparentequation\alph{equation}}%
}{%
\def\theequation{\theparentequation.\arabic{equation}}
}{\typeout{Success!}}{\typeout{Failed!}}

\makeatletter
\xpretocmd{\@schapter}{\setcounter{equation}{0}\setcounter{parentequation}{0}}{\typeout{Yes!}}{\typeout{Failed to patch \@schapter}}
\makeatother

\begin{document}
\chapter*{Problem 1}
\section*{Question 1}
\begin{subequations}
$$X = 8$$
$$y = 9$$
\end{subequations}
\section*{Question 2}
\begin{subequations}
$$A = 3$$
$$B = 5$$
\end{subequations}

\chapter*{Problem 2}
\section*{Question 1}
\begin{subequations}
$$C = 5$$
$$D = 0$$
\end{subequations}
\end{document}


Here's the \chapter version:

\documentclass{report}

\usepackage{xpatch}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\xpatchcmd{\subequations}{%
\def\theequation{\theparentequation\alph{equation}}%
}{%
\def\theequation{\theparentequation.\arabic{equation}}
}{\typeout{Success!}}{\typeout{Failed!}}

\usepackage{chngcntr}

\counterwithout{equation}{section}

\begin{document}
\chapter{Problem 1}
\section{Question 1}
\begin{subequations}
$$X = 8$$
$$y = 9$$
\end{subequations}
\section{Question 2}
\begin{subequations}
$$A = 3$$
$$B = 5$$
\end{subequations}

\chapter{Problem 2}
\section{Question 1}
\begin{subequations}
$$C = 5$$
$$D = 0$$
\end{subequations}

\end{document}

• I think I'd rather suggest using \chapter and \section rather than using the unnumbered forms and then having to patch everything else to cope. – David Carlisle Jan 31 '16 at 13:01
• @DavidCarlisle: That's true, but it's the O.P's design decision – user31729 Jan 31 '16 at 13:02
• That is indeed true, but my issue is that the document contains the answers of an exercise I have to make and therefore I would like to give the chapter different names, than Chapter 1. But having "chapter 1, and then Problem 1" below each other is a bit ugly, I would say – Student NL Jan 31 '16 at 13:04
• Suppose I change it to having the chapter numbers, it goes well, except for the fact that if I have equations in section 1 and section 3, then in section 3 it uses 1.2.1 instead of 1.3.1 (what I want) – Student NL Jan 31 '16 at 13:09
• @StudentNL: I don't understand your complaints – user31729 Jan 31 '16 at 13:10