Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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...

share|improve this question
    
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 at 16:28

3 Answers 3

up vote 2 down vote accepted

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}

enter image description here

share|improve this answer

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}

output1

Maybe

\documentclass{article}

\usepackage{mathtools}

\begin{document}

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

\end{document}

output2

is (more) useful?

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

share|improve this answer
    
What are the curly brackets doing here? –  user1729 Feb 11 at 15:07
1  
@user1729 They give the correct horizontal spacing. Try my examples; remove them and see what happens. :) –  Svend Tveskæg Feb 11 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 at 15:10
    
@user1729 As I say, try it. :) You'll learn much more by seeing it fo yourself. –  Svend Tveskæg Feb 11 at 15:12
1  
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 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}

enter image description here

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

share|improve this answer
1  
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 at 15:05
    
hehe, accept what ever you want. That was not such a great effort... –  LaRiFaRi Feb 11 at 15:06
2  
I disagree - this is a wonderful effort! Obvious and elegant is much better than complicated... –  user1729 Feb 11 at 15:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.