# Align equation number with any line within an equation environment?

Is there an environment / modification that:

1. Works within a display math environment begin{equation}
2. Allows for alignment of lines.
3. Allows equation number to be aligned with any specific line, e.g. the last of multiple aligned lines, instead of the equation number being vertically centered?

According to wikibooks, there are four environments from amsmath that works within display math:

gathered: Allows gathering equations to be set under each other and assigned a single equation number.

split: Similar to align, but used inside another displayed mathematics environment.*

aligned: Similar to align, to be used inside another mathematics environment.

alignedat: Similar to alignat, and likewise takes an additional argument specifying the number of columns of equations to set.

If I use any of those four environments within an , then I get a label centered around the whole math block. For example here with aligned

\begin{aligned} (a+b)^2 = (a + b)(a + b) \\ = a^2 + ab + ba + b^2 \\ = a^2 + 2ab + b^2 \end{aligned}


Can this number be aligned with any of the three lines, if it must happen within an equation environment?

Use case: Writing in Typora, only TeX notation $$...$$ gives a live preview for display math, and this is converted by pandoc into $$...$$, so I'm constrained to work in equation environment if I want live preview in-editor.

• Are you looking for \begin{align} with some \nonumber? Jun 25, 2018 at 23:55
• Welcome to TeX SX! Yes, it can be: use the optional argument [t] or [b] for the aligned environment. Jun 25, 2018 at 23:55
• @Bernard excellent! That will at least allow me to push it to the first or last line, which is what I want in 99% of cases where I don't want it centered. Out of curiosity, if I have more than 3 lines, can I customize the which line the equation number is aligned to, or are the three choices simply top ([t]), bottom ([b]) or centered (no optional argument)? Jun 26, 2018 at 0:21
• There are no other choices, but if you're allowed to use, say, align, you can use \notag for the lines you don't want to number. Also, you can try to play with the \raisetag command. Jun 26, 2018 at 0:33
• Alright. I assume that the usage \raisetag would have to be trial and error with regards to the amount of space added, and that it cannot 'snap' to align with different lines? Nonetheless, good to know. Jun 26, 2018 at 0:41

Here's a demo.

To your list of alignments within a display maths, you can add multlined, provided by mathtools, which is an extension of amsmath.

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\begin{aligned}[t] (a+b)^2 & = (a + b)(a + b) \\ & = a^2 + ab + ba + b^2 \\ & = a^2 + 2ab + b^2 \end{aligned}

\begin{aligned}[b] (a+b)^2 & = (a + b)(a + b) \\ & = a^2 + ab + ba + b^2 \\ & = a^2 + 2ab + b^2 \end{aligned}

\end{document}


• Had no idea that [b] and [t] could be applied to aligned for those results. Thanks, good to know! That solves my main issue. And your comment on the OP about raisetag provides probably the only dirty, but feasible workaround in the extremely rare cases that I would need the number aligned other than top, bottom or center. Side-note: Even though you load mathtools in your demo, you're not actually using it right? Jun 26, 2018 at 0:43
• Not really here (except it used to fix a couple of bugs in amsmath). It is quite recommended to load it if you can, as it adds quite useful commands and environments to amsmath. Jun 26, 2018 at 0:46
• I see. The reason I don't use it is again the constraints I put upon myself by wanting live preview in Typora, i.e. I try to stick with things that are MathJax compatible, which mathtools sadly isn't. Luckily I use align way more than multline :) Jun 26, 2018 at 1:04

By using amsmath several options may apply to this case.

Option I: lines aligned with equal signs and first and third lines are numbered

$$(a+b)^2 &= (a + b)(a + b) \\ &= a^2 + ab + ba + b^2 \nonumber\\ &= a^2 + 2ab + b^2$$


with all lines labeled as one unit

  $$\begin{split} (a+b)^2 &= (a + b)(a + b) \\ &= a^2 + ab + ba + b^2 \\ &= a^2 + 2ab + b^2 \end{split}$$


Option II: lines aligned with equal signs and second line shows a numbered equation

 \begin{align}
(a+b)^2 &= (a + b)(a + b) \nonumber\\
&= a^2 + ab + ba + b^2 \\
&= a^2 + 2ab + b^2 \nonumber
\end{align}


Option III: lines aligned with equal signs and set of equations labeled as one unit

\begin{align}
\begin{split}
(a+b)^2 &= (a + b)(a + b) \\
&= a^2 + ab + ba + b^2 \\
&= a^2 + 2ab + b^2 \\
\end{split}
\end{align}


Option III: lines aligned with equal signs and set of equations labeled as one unit

\begin{eqnarray}
(a+b)^2 &=& (a + b)(a + b) \\
&=& a^2 + ab + ba + b^2 \\
&=& a^2 + 2ab + b^2 \\
\end{eqnarray}

• Thank you for the suggestions. Option I doesn't work since & can't be used in an equation env. Option II doesn't really do anything to move the labels as was my question. Option III can't be used since align can't be inside of equation, and my constraint was that equation is the enclosing environment. Option IV is redundant since eqarray is generally just considered a bad version of the newer align and other sibling environments from amsmath. Jun 26, 2018 at 1:09