# Align \coloneqq and =

One thing that has infuriated me for a long time is this:

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\begin{document}
\begin{align}
x &\coloneqq a^2 + b^2\\
&= c^2
\end{align}
\end{document}


I just want to introduce a definition and then proceed with a calculation. But it looks horrible:

The \coloneqq and = are not aligned on the right hand side, and the formulas following are neither.

(Note: Putting the & on the other side of the equations gives the correct alignment, but the wrong spacing to the formulas on the right hand side)

• By the way, mathtools loads amsmath, so you don't have to load both. Sep 12, 2016 at 10:44
• And about the tag, tags without questions are deleted every day (I accidentally created a tag. How do I delete it?), so don't worry about that. Sep 12, 2016 at 10:47
• I have a simpler solution: avoiding ≔ ;-) Sep 12, 2016 at 17:10

Since align right-aligns the first field and left aligns the second, one must place the \coloneqq and subsequent = in the first align field so that they get right aligned.

However, align is set up to provide proper \mathrel spacing for &= constructs, but not =& constructs. Thus, in addition to placing \coloneqq and subsequent = at the end of the first align field of their respective rows, they must be suffixed with an empty {} placeholder prior to the & separator, so that the \mathrel character of these two symbols can be forced to provide the proper spacing following the symbols.

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{align}
x \coloneqq{}& a^2 + b^2\\
={}& c^2
\end{align}
\end{document}


• My life was futile without this. Thank you. Sep 12, 2016 at 10:45
• @Turion THe {} placeholder on one, the other, or both side(s) of a \mathrel object tells the \mathrel object to provide spacing as if something were there. Sep 12, 2016 at 10:47
• Then I wonder why no {} is needed when we put the & on the other side. Sep 12, 2016 at 10:52
• @Turion the align environment is designed to "catch" the case where the = follows the & and insert space appropriately. It is not set up for the case where the = precedes the & and thus, for this case, the {} must be added manually. Sep 12, 2016 at 11:02
• @Turion {} is automatically added at the beginning of the cell. Sep 12, 2016 at 11:02

Another simple solution with the very small package makebox, which puts its second argument in a box of the first argument width:

\documentclass{article}

\usepackage{mathtools}
\usepackage{makebox}

\begin{document}
\setlength\fboxsep{0pt}
\begin{align}
x &\coloneqq a^2 + b^2\\
&\mathrel{\makebox*{$\coloneqq$}{\hfill$=$}} c^2
\end{align}

\end{document}


Here is the definition of \coloneqq:

> \coloneqq=macro:
->\vcentcolon \mathrel {\mkern -1.2mu}=


We can place whatever precedes = inside \phantom:

\documentclass{article}

\usepackage{mathtools}

\begin{document}

\begin{align}
x &\coloneqq a^2 + b^2\\
&\phantom{\vcentcolon\mathrel{\mkern-1.2mu}}= c^2
\end{align}

\end{document}