178

I am using align*, but I still need an equation number. I know one solution is to use align and add \nonumber to all lines but the last. Is there a 'lazy' way to do it?

I searched a little and found similar ones suggesting use split: Show equation number only once in align environment

Unfortunately, due to the page break issue I have, I need to use align, because split won't auto page break, as described in Long equation does not page break.

7 Answers 7

199

Use \tag:

\documentclass{article}
\usepackage{amsmath}
\newcommand\numberthis{\addtocounter{equation}{1}\tag{\theequation}}
\begin{document}
\begin{align*}
a &=b \\
  &=c \numberthis \label{eqn}
\end{align*}
Equation \eqref{eqn} shows that $a=c$.
\begin{equation}
d = e
\end{equation}
\end{document}

See page 3 of the amsmath package documentation for details.

7
  • Why didn't you use \stepcounter or \refstepcounter instead of \addtocounter? Commented Aug 31, 2013 at 6:14
  • @PSTikZ --- \refstepcounter isn't needed, as the \ref value is set correctly already. \stepcounter is probably the best choice, to take care of subsidiary counters. I don't think I gave much thought to this when I composed the answer. Commented Sep 2, 2013 at 8:25
  • Your example works perfectly for me, thank you. I have a followup question though. How can I make the number on the same line than the last line of the euqation provided that the last line is longer normal align would allow (it does fit in align* though)
    – magu_
    Commented Mar 24, 2014 at 9:56
  • 1
    @magu_ Please post a new question with an example showing exactly what you want. I think I understand your question, but I'm not 100% sure. Also, other users (who may have better solutions than me) will see the new question, whereas they are unlikely to see new comments here. Commented Mar 24, 2014 at 12:04
  • 2
    This solution has a problem when combined with the cleveref package: The sorting of \numberthis-references does not work properly. See this question for further detail. If anyone knows a solution fixing this problem, please let me know. Commented Sep 30, 2016 at 15:32
63

Another option is to use align, and then use \nonumber, as mentioned in http://mirrors.dotsrc.org/ctan/info/math/voss/mathmode/Mathmode.pdf.

Example:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
a &=b \nonumber \\
b &=c
\label{eq:test}
\end{align}
Equation \eqref{eq:test} shows that $a=c$.
\end{document}
3
  • 9
    The user seems to want to use an align* environment, though. Your approach would involve a lot of \nonumber, if the align contains a lot of lines.
    – jub0bs
    Commented Feb 26, 2014 at 9:50
  • 10
    Welcome to TeX.SX! This answer, while technically correct, is already mentioned in the second sentence of the question; the asker is looking for a different solution.
    – ChrisS
    Commented Feb 26, 2014 at 9:51
  • I must have misread the question. I did not see that. Sorry. Commented Feb 27, 2014 at 13:03
21

Here are minimal working examples that I use. This is what I have as a header

\documentclass[12pt]{amsart}           
\usepackage{amsmath,amsfonts,amssymb}

Two equations each with separate equation numbers and separate reference labels

\begin{align}
        \dot{a} &  =2\alpha(t)\eta\label{classicalmotion1}\\
        \dot{\eta} &  =-2\gamma(t)a\label{classicalmotion2}%
\end{align}%

Two equations with a single equation number and a single reference label

\begin{equation}
        \begin{aligned}[b]
        \dot{A} &  =2i\alpha(t)B\\
        \dot{B} &  =2i\gamma(t)A
        \end{aligned}
\label{eqn2.qo}
\end{equation}

I am guessing you know how to do the one without equation numbers.

2
  • thanks! somewhat surprisingly putting the \label(eqn2.qo} before \begin{aligned} changed the position of the eqn number in my case... Commented Oct 26, 2014 at 16:38
  • 1
    @Xi'an -- putting the \label before the align might change the position of the equation number, but it will also give an incorrect value with \eqref. Commented Jul 13, 2017 at 1:50
3

Define a new environment based on align* that adds the equation number at the end.

\documentclass{article}
\usepackage[a6paper]{geometry}
\usepackage{amsmath}

\NewDocumentEnvironment{alignb}{b}{%
  \begin{align*}
  \refstepcounter{equation} #1 \tag{\theequation}
  \end{align*}
}{\ignorespacesafterend}

\allowdisplaybreaks

\begin{document}

Check the reference: \eqref{test}

\begin{alignb}
a &= b \\
  &= d \\
  &= e \\
  &= d \\
  &= e \\
  &= d \\
  &= e \\
  &= d \\
  &= e \\
  &= d \\
  &= e \\
  &= d \\
  &= e \\
  &= d \\
  &= e \\
  &= d \\
  &= e \\
  &= d \\
  &= e \\
  &= d \\
  &= e \\
  &= d \\
  &= e \\
  &= d \\
  &= e \\
  &= d \\
  &= e \\
  &= d \\
  &= e \\
  &= f \label{test}
\end{alignb}

\end{document}

I used a6paper so the picture is smaller, in order to show that page breaks are honored.

enter image description here

3
  • This is the lazy solution and requires more upvotes tbh. The only downside is that the editors (like Overleaf) don't know your environment and don't automatically adjust colors to your convenience. Commented May 7 at 10:27
  • I need to add a \relax affer \end{alignb} (\end{alignb}\relax) to avoid a strange little indentation in the following text (if there isn't a par break). Why? Can this be fixed?
    – Gabriele
    Commented Jun 30 at 21:08
  • @Gabriele You're right: I fixed the missing bit.
    – egreg
    Commented Jun 30 at 22:59
2

Another solution.

\begin{subequations}\label{eqn}
\begin{align*}
a &=b \\
  &=c \tag{\ref{eqn}} 
\end{align*}
\end{subequations}
2
  • 1
    Try having two equations like that, you will see that this code doesn't work.
    – user156344
    Commented Apr 5, 2019 at 13:44
  • 1
    @user156344: tried and it works as well (of course your need to change the equation labels). Commented Sep 10, 2019 at 13:58
1

Here is my stupid "lazy" solution:

\newcommand{\NNN}{\nonumber\\}
% . . .
\begin{align}
a & = b \NNN
  & = c \NNN
  & = d \\
v & = w \NNN
  & = x \NNN
  & = y \NNN
  & = z
\end{align}

I wish align* be extended to allow for a \number command. That would be a mirror image, sort of, of align.

1

The environment {DispWithArrows} of witharrows, which is similar to {align} provides a key tagged-lines to control which lines will be tagged. With tagged-lines=last, only the last line is tagged.

\documentclass{article}
\usepackage{amsmath}
\usepackage{witharrows}

\begin{document}
\begin{DispWithArrows}[tagged-lines=last]
a &=b \\
  &=c \label{eqn}
\end{DispWithArrows}
Equation \eqref{eqn} shows that $a=c$.
\begin{equation}
d = e
\end{equation}
\end{document}

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .