3

The user egreg has posted a nice approach on how to increase equation numbers within subequations.


Minimum Working Example (MWE):

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}

\newcommand{\advanceparent}{%
  \stepcounter{parentequation}%
  \setcounter{equation}{0}%
  \xdef\theparentequation{\arabic{parentequation}}%
}

\begin{document}
    \begin{subequations}
        \begin{alignat}{3}
            \advanceparent
            && 1 & =1 &\quad & (\text{Example text}) \\
            && 2 & =2 &      & (\text{Example text}) \\
            \advanceparent
            && 3 & =3 &      & (\text{Example text}) \\
            && 4 & =4 &      & (\text{Example text})
        \end{alignat}
    \end{subequations}
\end{document}

Screenshot of the result:

Screenshot of the result


Description of the issue:

As you can see in the screenshot, even the very first equation begins with no. 2 instead of no. 1. I have tried to repair this behavior, but I don't get the issue fixed.

How to fix the code so numbering will begin with no. 1 and does continue numbering order of the previous document?

4
  • 1
    Well, the \advanceparent makes sense only in the middle of subequations, not at the very beginning...
    – campa
    Commented Apr 1, 2019 at 13:48
  • @campa: Yes, I thought the same. But even removing the very first \advanceparent-part does not change the numbering scheme.
    – Dave
    Commented Apr 1, 2019 at 13:51
  • 1
    Yes, that's one of the possible \xdef vs \gdef issues @daleif meant in his answer to your previous question :-)
    – campa
    Commented Apr 1, 2019 at 13:54
  • @campa: Oh my... :-) Sometimes LaTeX is everything else but not handy. :-)
    – Dave
    Commented Apr 1, 2019 at 13:57

2 Answers 2

2

The subequations environment allows to use \label just after it starts, in order to refer to the parent number globally. The idea is exploited in the linked answer.

You don't need this, so you have to explicitly start the business.

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{etoolbox}

\newcommand{\advanceparent}{%
  \stepcounter{parentequation}%
  \startparent
}
\newcommand{\startparent}{%
  \setcounter{equation}{0}%
  \xdef\theparentequation{\arabic{parentequation}}%
}

\begin{document}

\begin{subequations}
\begin{alignat}{2}
\startparent
1 & =1 &\quad & \text{(Example text)} \\
2 & =2 &      & \text{(Example text)} \\
\advanceparent
3 & =3 &      & \text{(Example text)} \\
4 & =4 &      & \text{(Example text)}
\end{alignat}
\end{subequations}
\end{document}

enter image description here

1

You can decrease the counter inside of the subequation environment:

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}

\newcommand{\advanceparent}{%
  \stepcounter{parentequation}%
  \setcounter{equation}{0}%
  \xdef\theparentequation{\arabic{parentequation}}%
}

\begin{document}
    \begin{subequations}
        \addtocounter{parentequation}{-1}%
        \begin{alignat}{3}
            \advanceparent
            && 1 & =1 &\quad & (\text{Example text}) \\
            && 2 & =2 &      & (\text{Example text}) \\
            \advanceparent
            && 3 & =3 &      & (\text{Example text}) \\
            && 4 & =4 &      & (\text{Example text})
        \end{alignat}
    \end{subequations}

\end{document}

enter image description here

If you don't want to do that manually at every set of equations, then you can hook it into the environment with etoolbox. In the example I have used the begin of alignat because the begin of subequations is still too early (the counter is setup after that).

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}

\usepackage{etoolbox}
\AtBeginEnvironment{alignat}{\addtocounter{parentequation}{-1}}

\newcommand{\advanceparent}{%
  \stepcounter{parentequation}%
  \setcounter{equation}{0}%
  \xdef\theparentequation{\arabic{parentequation}}%
}

\begin{document}
    \begin{subequations}
        %\addtocounter{parentequation}{-1}% no longer needed
        \begin{alignat}{3}
            \advanceparent
            && 1 & =1 &\quad & (\text{Example text}) \\
            && 2 & =2 &      & (\text{Example text}) \\
            \advanceparent
            && 3 & =3 &      & (\text{Example text}) \\
            && 4 & =4 &      & (\text{Example text})
        \end{alignat}
    \end{subequations}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .