14

I am using the align* environment to write equations expanding several lines. I would like to define a command sequence in the preamble, such that the last equation of this block will always be numbered (while the others remain unnumbered). For example, the block

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
x & =2+2\\
 & =3+1\\
 & =4
\end{align*}
\end{document}

will visually look like:

x = 2+2
  = 3+1
  = 4     (1)
David Carlisle
  • 757,742
Sam
  • 143
  • 1
    Welcome to TeX.sx! It's always the best adding minimal working example (MWE) that illustrates your problem. I hope next time you will provide one. – Marco Daniel Aug 11 '12 at 11:28
  • @MarcoDaniel: Is a MWE really appropriate in this case? They don't have a problem, but something they wish to achieve. It's pretty clear to me from just what the OP has written, what they're looking for. – Niel de Beaudrap Aug 11 '12 at 12:21
  • @NieldeBeaudrap: I think so. It's easier to copy paste a mwe. – Marco Daniel Aug 11 '12 at 12:23
  • @MarcoDaniel: I suppose that, because amsmath is my bread and butter, it's almost as easy for me to open a new article in my editor of choice, paste that equation, and then manually write the missing \usepackage{amsmath} which I know goes there anyway. For anything moderately complicated, or using many/obscure packages, I'd agree; but I grasp simple problems like this one more quickly when it's a code snippet whose context is obvious, than a compilable document (as in my recent revision) in which 60% of the content is something which I would have known goes there anyhow. – Niel de Beaudrap Aug 11 '12 at 12:36

5 Answers5

35

What you want is aligned with bottom vertical alignment:

\documentclass{report}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}[b]
x & =2+2\\
  & =3+1\\
  & =4
\end{aligned}
\end{equation}
\end{document}

enter image description here

Torbjørn T.
  • 206,688
egreg
  • 1,121,712
16

It's easier suppressing the first lines. Every line ends up with \\ except the last one. So simple redefine \\ inside the environment align.

\documentclass{report}
\usepackage{amsmath}
\makeatletter
\def\Let@{\def\\{\notag\math@cr}}
\makeatother
\begin{document}
\begin{align}
x & =2+2\\
  & =3+1\\
  & =4
\end{align}
\end{document}

enter image description here

Torbjørn T.
  • 206,688
Marco Daniel
  • 95,681
14

I'm a little surprised no one has gone for the 'simple' solution involving \notag

screenshot

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
x & =2+2\notag\\
  & =3+1\notag\\
  & =4
\end{align}
\end{document}
Torbjørn T.
  • 206,688
cmhughes
  • 100,947
  • In fact the approved solution by @Marco Daniel uses notag. I started your way, but I grew tired and did something similar, defined \n as \notag\ so I can use \n or \ depending if I want numbering or not. – JorgeGT Aug 11 '12 at 21:34
5

You may define an environment based on align* which does what you want. I'll call it Salign.

\documentclass[11pt]{article}
\usepackage{amsmath}

\newcommand*{\starnr}{\stepcounter{equation}\tag{\theequation}}
\makeatletter
\newenvironment{Salign}
  {\start@align\@ne\st@rredtrue\m@ne}
  {\starnr\endalign}
\makeatother

\begin{document}
\begin{Salign}
  x&=2+2\\
   &=3+1\\ 
   &=4
\end{Salign}

\end{document}

enter image description here

Torbjørn T.
  • 206,688
  • +1 for the idea with \stepcounter. I really miss something like \dotag which would perform this automatically. – yo' Aug 12 '12 at 20:34
-1

use a tag after the last equation

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
x & =2+2\\
& =3+1\\
& = 4  \tag{1}
\end{align*}
\end{document}

enter image description here

this solution work for me

Joshua
  • 1
  • I happen to be changing my code indentation, thanks for your help. – Joshua May 05 '17 at 14:17
  • You could improve your answer by making the code into a complete compilable example, by adding the pre-amble and document environment. – Thruston May 05 '17 at 14:36
  • This solution is slightly less desirable as it does not take the automatic equation numbering into account. If say, you add in another (numbered) equation below this, it will turn up as (1), not (2) as it should. This requirement wasn't stipulated explicitly by OP, but just something to note, I guess. – Troy May 05 '17 at 14:42
  • Yes, i understand the advantage of marking the tag in implicit way. My solution is a dirty way. In some situation, the tag is static and complicated, like (8.21), and I have to explicitly refer it many times in my article. For simplicity, i just want to write it down in explicit way. – Joshua May 06 '17 at 03:02