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.

I am trying to use subequations inside an array environment. Specifically, I am trying to create an array that has both regular numbered equations and subequations. I am looking to create an array that has the appearance:

A + B --> C + D       (1.1)
E + F --> G + H       (1.2)
I + J --> K + L       (1.3a)
      --> M + N       (1.3b)
      --> O + P       (1.3c)

The first two reactions (equations) in the array are numbed regularly, but the final three represent branching so I'd like to label them as subequations and be able to reference them as such.

Any ideas?

share|improve this question
    
I assume by "array" you actually refer to align, and that the structure should just be array-like, since LaTeX has an array environment. –  Werner Nov 12 '11 at 8:57
add comment

migrated from stackoverflow.com Nov 12 '11 at 13:00

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 6 down vote accepted

Here's a way using \tags 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.

enter image description here

\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.

share|improve this answer
    
Thanks... this worked nicely. While a fair amount of code is required in the preamble, this is a nice solution since its usage in the align environment is clean. –  BFTM Dec 20 '11 at 23:00
add comment

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.

enter image description here

This solution required a few tweaks:

  1. I added a \phantom{a} to get the first align environment to adjust for the extra character that will be in the equation numbers.

  2. 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.

  3. 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}
share|improve this answer
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.