# How can I align this properly?

I want the equal sign aligned in the middle of the page and the -2ab completely to the right. This is what I have:

\begin{align*}
(a+b)^2 & =  4 \cdot \frac{1}{2} ab + c^2  \\
a^2 + 2ab + b^2 & = \cdot 2ab + c^2  & \vert - 2ab\\
a^2 + b^2 & = c^2
\end{align*}


I already tried the \flushright and the \equation*command, but they don't work.

Two ways: abusing \tag and using flalign. (BTW the \cdot after the equal sign looks misplaced.)

% twocolumn for smaller snapshot
\documentclass[twocolumn]{article}

\usepackage{amsmath}

\begin{document}

Abusing \verb+\tag+
\begin{align}
(a+b)^2 & =  4 \cdot \frac{1}{2} ab + c^2 \nonumber \\
a^2 + 2ab + b^2 & = \cdot 2ab + c^2 \tag*{$\mid - 2ab$} \\
a^2 + b^2 & = c^2 \nonumber
\end{align}
or with \verb+flalign*+
\begin{flalign*}
&&  (a+b)^2 & =  4 \cdot \frac{1}{2} ab + c^2 \\
\phantom{ \mid- 2ab}&&  a^2 + 2ab + b^2 & = \cdot 2ab + c^2 & \mid - 2ab \\
&&  a^2 + b^2 & = c^2
\end{flalign*}
This is what happens with the second one if you don't use \verb+\phantom+
\begin{flalign*}
&&  (a+b)^2 & =  4 \cdot \frac{1}{2} ab + c^2 \\
&&  a^2 + 2ab + b^2 & = \cdot 2ab + c^2 & \mid - 2ab \\
&&  a^2 + b^2 & = c^2
\end{flalign*}

\end{document}


Note that I used \mid instead of \vert: note the different spacing

$\mid-2ab$ vs. $\vert-2ab$

• Thank you! Yes, the cdot was misplaced. May 13, 2021 at 13:40