Mixed (sub)equation numbering within an array
Here's a way using \tag
s for the subequations.
The amsmath
package provides \tag{<stuff>}
which prints (<stuff>)
as the equation label. Additionally, it does not increment the equation counter, since it is not needed.
This behaviour is exploited in the following MWE which provides \subeqn
as a "tag" for each subequation, and it should be used with each subequation. The printed tag is an updated equation number, with the subequation number appended. Referencing works as expected, since the tag is referenced in its entirety, just like with regular labelling/referencing.
The advantage with this approach is that alignment is kept since there is no switch of environments. Marginal clutter within the align
environment's "subequation area" may be the only drawback.
\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\AtBeginEnvironment{align}{\setcounter{subeqn}{0}}% Reset subequation number at start of align
\newcounter{subeqn} \renewcommand{\thesubeqn}{\theequation\alph{subeqn}}%
\newcommand{\subeqn}{%
\refstepcounter{subeqn}% Step subequation number
\tag{\thesubeqn}% Label equation
}
\begin{document}
\begin{align}
A + B &\to C + D \\
E + F &\to G + H \label{eq:EFGH} \\
I + J &\to K + L \refstepcounter{equation}\subeqn \\
&\to M + N \subeqn \label{eq:MN}\\
&\to O + P \subeqn
\end{align}
The EFGH equation is \eqref{eq:EFGH} and the MN is equation~\eqref{eq:MN}.
\end{document}
The etoolbox
package was used to reset the subequation counter at the start of every align
environment, for consistency. Otherwise subequation numbers would resume if used in subsequent align
environments.
If you need to avoid using the etoolbox
package, then you could use the following preamble:
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\newcounter{subeqn} \renewcommand{\thesubeqn}{\theequation\alph{subeqn}}%
\makeatletter
\@addtoreset{subeqn}{equation}
\makeatother
\newcommand{\subeqn}{%
\refstepcounter{subeqn}% Step subequation number
\tag{\thesubeqn}% Label equation
}
This resets the subeqn
counter with every increment of the equation
counter. Note that in both instances, a \refstepcounter{equation}
is required in order to obtain the correct equation number for the subequations.
The subequations
environment can be used to get the align
environment to label the second set of equations as you desire. To reference the equations, add \label{eq:EFGH}
at the end of the equation. Then when you want to refer to them use \eqref{eq:EFGH}
. Any text can go inside the \label
and here I have added a prefix eq:
so that I know that the reference I am referring to is an equation. And you should use \eqref
instead of just \ref
so that the equation is referred to in the same way it was labelled (i.e., with the parenthesis).
Also, keep in mind that the first time you process this the equation references will show up as (??)
. A subsequent run (do not delete the .aux files from the first run) will result show the actual equation numbers.
This solution required a few tweaks:
I added a
\phantom{a}
to get the first align environment to adjust for the extra character that will be in the equation numbers.The
AdjustSize
macro is used to ensure that in the second set of equations we use as much space on the left as we did in the first to get the arrows to be aligned.The
\vspace{-3\abovedisplayskip}
was added to eliminate the additional space that was added in between the two equation sections.
Here is the code
\documentclass[border=5pt,tightpage]{standalone}
\usepackage{calc}% Needed for the \widthof macro
\usepackage{amsmath}
\begin{document}
\newcommand*{\AdjustSize}[1]{\makebox[\widthof{\ensuremath{A+B}}][c]{#1}}%
%
\noindent
\begin{align}
A + B &\to C + D \phantom{a}\\
E + F &\to G + H \label{eq:EFGH}
\end{align}
\begin{subequations}\vspace{-3\abovedisplayskip}
\begin{align}
\AdjustSize{I + J}&\to K + L\\
&\to M + N \label{eq:MN}\\
&\to O + P
\end{align}
\end{subequations}
%
The EFGH equation is \eqref{eq:EFGH} and the MN is equation~\eqref{eq:MN}.
\end{document}
In addition to Werner's answer, I'd like to suggest defining the following command:
\newcommand{\beginsubeqn}{\setcounter{subeqn}{0}\refstepcounter{equation}\subeqn}
which would tidy up usage to the following:
\begin{align}
A + B &\to C + D \\
E + F &\to G + H \label{eq:EFGH} \\
I + J &\to K + L \beginsubeqn \\
&\to M + N \subeqn \label{eq:MN}\\
&\to O + P \subeqn
\end{align}
A new major numbering can be started within the same align
environment by invoking \beginsubeqn
again. The answer is also packaged here.