7

If I am using align to display an equation and have each line numbered, how do I reset the align counter?

As is, even if I use \end{align} and later in the document have a second \begin{align}, the counter continues from where it left off, instead of starting at 1.

Is there any simple way to do this? Or would I be better off creating my own counter and not using align?

Edit: More specifically, I am this to show lines/steps on a solution to homework problems. Separate occurrences of (1) will be in answers to different problems, so there should not be any trouble distinguishing.

  • 3
    You know that you may have many duplicately-labelled equations then. How would people distinguish between equation (1) and (1)? – Werner Jan 18 '17 at 5:51
  • More specifically, I am this to show lines/steps on a solution to homework problems. Separate occurrences of (1) will be in answers to different problems, so there should not be any trouble distinguishing. – Snoah Jan 19 '17 at 3:02
  • Okay, in that regard one can set the equation counter to be reset with every one of your problems. What do you use to create your problems? Any special package? Just a plain enumerate? – Werner Jan 19 '17 at 3:40
  • Just a plain align at the moment, unfortunately. This is my second time using Latex. Should I look at details on the enumerate environment instead of my current question? – Snoah Jan 19 '17 at 17:36
5

I'm not sure why you want to do it as you will have multiple of the same equation markers in your document, but it is possible to hook into the start of the align environment with etoolbox. You have to pay attention though, as other environments will not reset the counter.

\documentclass{article}

\usepackage{amsmath}
\usepackage{etoolbox}
\AtBeginEnvironment{align}{\setcounter{equation}{0}}

\begin{document}

\begin{align}
  a &= b\\
  a &= 2c
\end{align}

\begin{align}
  a &= b\\
  a &= 4d
\end{align}

\begin{equation}
  a = 6e
\end{equation}

\end{document}

output sample

4

The package amsmath which gives you align also provides subequations:

Sample output

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{subequations}
  \begin{align}
    x &= y\\
    &=z
  \end{align}
\end{subequations}

\begin{subequations}
  \begin{align}
    a &= b\\
    &=c
  \end{align}
\end{subequations}

\end{document}
1

There is no align counter, but you can always create one.

\documentclass{article}
\usepackage{mathtools}

\newcounter{align}[equation]
\renewcommand{\thealign}{\theequation.\arabic{align}}
\newcommand{\alignno}{\refstepcounter{align}\tag{\thealign}}

\expandafter\let\expandafter\oldalignstar\csname align*\endcsname
\expandafter\def\csname align*\endcsname{\refstepcounter{equation}\oldalignstar}

\begin{document}
Some text here
\begin{align*}
  x &= a \alignno\\
  y &= b \alignno\\
\end{align*}
somr text here
\begin{align*}
  u &= c \alignno\\
  v &= d \alignno\\
\end{align*}
and some more text.
\end{document}

demo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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