# How to align the middle of some words

I want to align the middle of a "word" with something else. Let me explain. The following is what I have.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
a&:=b\\
c&=d
\end{align*}
\end{document}


This looks okay, but I really want the two equal signs to be what we are aligning. So the obvious thing to do is to more the & to the other side of the :, as follows.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
a:&=b\\
c&=d
\end{align*}
\end{document}


But, of course, this was never going to work! You end up with a space between the colon and the equals sign, : = as opposed to :=. So you see my problem...

-
Thanks for accepting my answer. You should know that I just uploaded the tabstackengine package to CTAN within the last hour, and so it should be available for download (including documentation) in the coming days. – Steven B. Segletes Feb 11 '14 at 16:28

This is using the under-development tabstackengine package, first introduced here at Writing a table with equally spaced columns, based on the widest column (source code available at Measuring align).

The package extends the stackengine package by adding tabbing capability. This answer, Can I tab inside of align environment?, gives some of the syntax of the package. I apologize that I have been lax in completing the package and getting it out the door, so the only way to see it in action is by searching this site for tabstackengine.

\documentclass{article}
\usepackage{tabstackengine}
\usepackage{amsmath}
\stackMath
\begin{document}
\begin{equation*}
\setstacktabulargap{0pt}
\tabularCenterstack{lrl}{%
a&:=&b\\
c&=&d
}
\end{equation*}
\end{document}


-

Is the following what you are looking for?

\documentclass{article}

\usepackage{mathtools}

\begin{document}

\begin{align*}
a \coloneqq{} &b\\
c ={}         &d
\end{align*}

\end{document}


Maybe

\documentclass{article}

\usepackage{mathtools}

\begin{document}

\begin{alignat*}{2}
&a &{}\coloneqq{} &b\\
&c &{}={}         &d
\end{alignat*}

\end{document}


is (more) useful?

Note: \coloneqq from mathtools gives the correct symbol for dynamic definition (or whatever it is).

-
What are the curly brackets doing here? – user1729 Feb 11 '14 at 15:07
@user1729 They give the correct horizontal spacing. Try my examples; remove them and see what happens. :) – Svend Tveskæg Feb 11 '14 at 15:08
I figured that that was approximately what they did, but I do not understand what you mean by "correct". Do they put a single space between the end of one row and the beginning of next? – user1729 Feb 11 '14 at 15:10
@user1729 As I say, try it. :) You'll learn much more by seeing it fo yourself. – Svend Tveskæg Feb 11 '14 at 15:12
A mathematical relation at the beginning or end of a math environment is not treated as a relation (is not surrounded by "relation space"). The braces supply something on the other side so it is treated as a relation and so surrounded by space. The AMS alignment environments supply their own {} after the & so they are not needed for things like &=, although they would not do any harm. – Dan Feb 11 '14 at 22:31

If a bigger space in the second equation is acceptable, the following is working quite easy. In this very case, the right side aligning of the left terms actually looks quite nice.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
a&:=b\\
c&\phantom{:}=d
\end{align*}
\end{document}


For the use of the better looking \coloneqq of the package mathtools, just align on the right side of the equations: ={}&

-
This is the perfect fix for my own situation. Thanks! Although I feel that one of the other answers will be of more help to others so I hope you are not offended when I don't accept yours... – user1729 Feb 11 '14 at 15:05
hehe, accept what ever you want. That was not such a great effort... – LaRiFaRi Feb 11 '14 at 15:06
I disagree - this is a wonderful effort! Obvious and elegant is much better than complicated... – user1729 Feb 11 '14 at 15:08