0

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}}
\begin{equation}
X = 8
\end{equation}

\begin{equation}
y = 9
\end{equation}
\end{subequations}

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

\begin{equation}
B = 5
\end{equation}
\end{subequations}


\chapter*{Problem 2}

\section*{Question 1}

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

\begin{equation}
D = 0
\end{equation}
\end{subequations}

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

\begin{equation}
F = 6
\end{equation}
\end{subequations}

\end{document}

How can I change this?

Thanks in advance!

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}}
    \begin{equation}
    X = 8
    \end{equation}

    \begin{equation}
    y = 9
    \end{equation}
    \end{subequations}

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

    \begin{equation}
    B = 5
    \end{equation}
    \end{subequations}


    \chapter{Problem 2}

    \section{Question 1}

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

    \begin{equation}
    D = 0
    \end{equation}
    \end{subequations}

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

    \begin{equation}
    F = 6
    \end{equation}
    \end{subequations}

    \end{document}

closed as unclear what you're asking by user31729, Maarten Dhondt, Henri Menke, darthbith, Martin Schröder May 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.

  • 3
    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
  • I'm quite new and I'm not sure how to do this. \documentclass{report} \usepackage[utf8]{inputenc} \usepackage{amsmath} \begin{document} \maketitle \chapter*{Problem 1} \section*{Question 1} \begin{subequations} \renewcommand{\theequation}{\theparentequation.\arabic{equation}} \begin{equation} X = 8 \end{equation} \begin{equation} y = 9 \end{equation} \end{subequations} \section*{Question 2} \begin{subequations} \renewcommand{\theequation}{\theparentequation.\arabic{equation}} \begin{equation} A = 3 \end{equation} \begin{equation} B = 5 \end{equation} \end{subequations} – Student NL Jan 31 '16 at 12:29
  • \chapter*{Problem 2} \section*{Question 1} \begin{subequations} \renewcommand{\theequation}{\theparentequation.\arabic{equation}} \begin{equation} C = 5 \end{equation} \begin{equation} D = 0 \end{equation} \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
  • 1
    @StudentNL: Your question is badly worded, edit your question and explain better your problem so we can help you. – ricardoramos Feb 9 '16 at 0:53
3

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

\numberwithin{equation}{section}

enter image description here

\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
    \begin{equation}
    X = 8
    \end{equation}

aaa
    \begin{equation}
    y = 9
    \end{equation}

    \section{Question 2}
aaa
    \begin{equation}
    A = 3
    \end{equation}
aaa
    \begin{equation}
    B = 5
    \end{equation}


    \chapter{Problem 2}

    \section{Question 1}
aaa
    \begin{equation}
    C = 5
    \end{equation}
aaa
    \begin{equation}
    D = 0
    \end{equation}

    \section{Question 2}
    \section{Question 3}
aaa
    \begin{equation}
    E = 1
    \end{equation}
aa
    \begin{equation}
    F = 6
    \end{equation}


    \end{document}
  • Voting up, since nobody else appreciates your answer ;-) – user31729 Feb 2 '16 at 21:09
1

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}
\begin{equation} 
    X = 8 
  \end{equation} 
  \begin{equation} 
    y = 9 
  \end{equation} 
\end{subequations} 
\section*{Question 2} 
\begin{subequations} 
  \begin{equation} 
    A = 3 
  \end{equation} 
  \begin{equation} 
    B = 5 
  \end{equation} 
\end{subequations} 


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

enter image description here

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}
\begin{equation} 
    X = 8 
  \end{equation} 
  \begin{equation} 
    y = 9 
  \end{equation} 
\end{subequations} 
\section{Question 2} 
\begin{subequations} 
  \begin{equation} 
    A = 3 
  \end{equation} 
  \begin{equation} 
    B = 5 
  \end{equation} 
\end{subequations} 


\chapter{Problem 2}
\section{Question 1} 
\begin{subequations} 
\begin{equation} 
  C = 5 
\end{equation} 
\begin{equation} 
  D = 0 
\end{equation} 
\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

Not the answer you're looking for? Browse other questions tagged or ask your own question.