Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In a document, I use the subequations environment inside another subequations environment - to e.g. have equations numbered as (1a), (1b), (1ca), (1cb), (1d) etc. At an overall level, all the equations belong together, hence they all have number (1), and furthermore, at a nested level, the two (1c) equations belong together, hence (1ca) and (1cb). This all works fine, but the equations that then follow - which should be (2), (3) etc. - get different numbers. In the example below, the last equation outside all of the subequations should be number (2), but when I compile it it gets number (5).

I suppose there is some conflict causing the wrong numbering, but could anyone tell me how I obtain the correct numbering?

The code is as follows:

\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}
\section{Section}
\begin{subequations}
These equations are numbered as subequations:
\begin{align}
F &= m a \\
p & = mv
\end{align}
These equations are also numbered as subequations, and they are numbered correctly:
% % %
\begin{subequations}
\begin{align}
F &= m a \\
p & = mv
\end{align}
\end{subequations}
\begin{subequations}
\begin{align}
F &= m a \\
p & = mv
\end{align}
\end{subequations}
\end{subequations}
But the next equation is then not numbered correctly; It should have number (2):
\begin{align}
F &= ma
\end{align}

\end{document}
share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

You should define a subsubequations environment: the problem is that at every \begin{subequations} the "original" equation counter is stepped and its value is remembered to be restored at \end{subequations}. Since in your document there are three \begin{subequations}, the number of the next equation ends to be 5.

\documentclass[10pt,a4paper]{article}

\usepackage{amsmath}

\makeatletter
\newcounter{parentsubequation}% Counter for ``parent equation''.
\newenvironment{subsubequations}{%
  \refstepcounter{equation}%
  \protected@edef\theparentsubequation{\theequation}%
  \setcounter{parentsubequation}{\value{equation}}%
  \setcounter{equation}{0}%
  \def\theequation{\theparentsubequation\alph{equation}}%
  \ignorespaces
}{%
  \setcounter{equation}{\value{parentsubequation}}%
  \ignorespacesafterend
}
\makeatother

\begin{document}
\section{Section}
\begin{subequations}
These equations are numbered as subequations:
\begin{align}
F &= m a \\
p & = mv
\end{align}
These equations are also numbered as subequations, and they are numbered correctly:
% % %
\begin{subsubequations}
\begin{align}
F &= m a \\
p & = mv
\end{align}
\end{subsubequations}
\begin{subsubequations}
\begin{align}
F &= m a \\
p & = mv
\end{align}
\end{subsubequations}
\end{subequations}
But the next equation is then not numbered correctly; It should have number (2):
\begin{align}
F &= ma
\end{align}

\end{document}
share|improve this answer
    
Thank you, both for a quick answer and for a well working solution! –  user15272 Jun 4 '12 at 12:53
    
@user15272: If this answers your question, you can mark the question as answered by clicking the tick mark next to egreg's answer. You should also upvote answers (and questions) that you find helpful by clicking the upward pointing arrow next to the posts. –  Jake Jun 21 '12 at 15:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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