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.

Consider the following MWE:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\setcounter{equation}{42}

\begin{align}
                 a & = b + c              \label{label1} \\
    \alpha_{i,j,k} & = \theta^2 + \phi^2  \label{label2} \\
      M_\text{res} & = a + \alpha_{i,j,k} \label{label3}
\end{align}

\end{document}

How can I enumerate the three equations? Wrapping the align environment in an enumerate environment and starting each equation line with \item won't work.

The equations should be enumerated like normal, and will thus depend on what comes before the align environment in question. I've arbitrarily set the equation counter to 42 to represent the content before the align. I also need to reference the equation labels as normal.

share|improve this question
    
Don't they have already a number? –  egreg Sep 4 at 15:58
    
@egreg: They do have automatic numbering, which depends on what comes before the align environment. I need to enumerate the three equations as 1., 2. and 3. on the left hand side. –  eiterorm Sep 4 at 16:01
    
What's the reason? I see none. –  egreg Sep 4 at 16:01
    
@egreg: I'm outlining the mathematical steps of numerical algorithms. –  eiterorm Sep 4 at 16:03
    
Do you need to refer to those numbers? –  egreg Sep 4 at 16:03

2 Answers 2

up vote 4 down vote accepted

Use alignat and a \step macro:

\documentclass{article}
\usepackage{amsmath}

\newcounter{step}
\newcommand{\step}{\stepcounter{step}\thestep.\quad}

\begin{document}

\setcounter{equation}{42}

\setcounter{step}{0} % do this when you want to reset the numbering
\begin{alignat}{2}
\step&&              a & = b + c              \label{label1} \\
\step&& \alpha_{i,j,k} & = \theta^2 + \phi^2  \label{label2} \\
\step&&   M_\text{res} & = a + \alpha_{i,j,k} \label{label3}
\end{alignat}

\end{document}

enter image description here

share|improve this answer
1  
Surely there is a way to push the left number to the margin. –  John Kormylo Sep 4 at 16:33
    
@John Kormylo: See my answer. –  Bernard Sep 4 at 16:35
    
@egreg: Don't forget to reset the counter on entering of leaving the environment. –  Bernard Sep 4 at 16:37
    
@Bernard Isn't \setcounter{step}{0} before the environment? ;-) –  egreg Sep 4 at 16:54
    
@JohnKormylo That would be an abomination. –  egreg Sep 4 at 16:55

A solution that uses the flalign environment:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\newcounter{algostep}
\newcommand\step{\stepcounter{algostep}\hskip\parindent\thealgostep.}
\usepackage{etoolbox}
\BeforeBeginEnvironment{flalign}{\setcounter{algostep}{0}}

\begin{document}
\setcounter{equation}{42}
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.
    \begin{flalign}
&\step & a & = b + c \label{label1} & \\
&\step & q & = e + f \label{label2} \\
&\step & z & = a + d \label{label3}
\end{flalign}
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.
\begin{flalign}
&\step & z & = a + d \label{label3} & \\
&\step & q & = e + f \label{label2} \\
&\step & a & = b + c \label{label1}
\end{flalign}

\end{document}

enter image description here

share|improve this answer
    
Thanks for the nice solution. This compiles nicely on its own, but sadly, somewhere in my main document, something is causing an error with \gappto when using your solution. –  eiterorm Sep 4 at 17:00
    
Could you produce a MWE so we can test? –  Bernard Sep 4 at 18:04
    
I can't seem to pinpoint the error. It's none of the packages themselves, so there has to be something in my document causing the error. –  eiterorm Sep 5 at 12:17

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.