# Make align* number the last equation

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)

-
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

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}


-
Hi. This solution works best for me. Thanks! –  Sam Aug 11 '12 at 19:42
+1 but for every align? what happens if they want to turn the behaviour off? –  cmhughes Aug 11 '12 at 21:00
@cmhughe: You can add a simple switch like \def\changenumberingon{\def\Let@{\def\\{\notag\math@cr}} and \def\changenumberingoff{\def\Let@{\def\\{\notag\math@cr}} –  Marco Daniel Aug 11 '12 at 21:05

What you want is aligned with bottom vertical alignment:

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


-
This is something which I wish I had known quite some time ago! –  Niel de Beaudrap Aug 11 '12 at 12:22
@NieldeBeaudrap: Me too –  Marco Daniel Aug 11 '12 at 12:26
This is perhaps the simplest. Thanks! I actually work with LyX so I prefer to redefine the align* environment. But in LaTeX it seems to me like the best option. –  Sam Aug 11 '12 at 19:44

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

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

-
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

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}


-
+1 for the idea with \stepcounter. I really miss something like \dotag which would perform this automatically. –  tohecz Aug 12 '12 at 20:34