# Can you format these equations for me?

Can help me formatting these (example and non-sense) equations?

\begin{eqnarray*}
z + t = b \quad \forall x \in X \\
h + g(a,b,c) + r\cdot a = f(b,c,d) \quad \forall y \in Y \\
a = b \quad \forall z \in Z \\
u \cdot v = h + q \forall n \in \mathbb N
\end{eqnarray*}


I would like to have the equality signs one below the other, the left side of the equalities aligned right towards the signs, the right term aligned left to the equality signs, and the forall-signs one below the other.

I did not manage to format this in the appropiate way. Any explanation why your solution works is appreciated as well.

-
Please add a document class and all necessary packages (but only necessary ones) to your code so other users don't have to guess that. (You'll have a minimal working example (MWE) then.) An image of the output would also be great. –  doncherry Apr 6 '12 at 10:51
Thank, I haven't been aware of this convention on this site. This will be added soon. –  Martin Apr 6 '12 at 13:09

Never use eqnarray, never. Load the amsmath package to get its powerful alignment environments:

\begin{align*}
z + t                   &= b        &&\forall x \in X \\
h + g(a,b,c) + r\cdot a &= f(b,c,d) &&\forall y \in Y \\
a                       &= b        &&\forall z \in Z \\
u \cdot v               &= h + q    &&\forall n \in \mathbb{N}
\end{align*}


The spaces in the input are irrelevant, but are helpful to spot alignment point.

An align environment and its sibling align* (the latter doesn't number lines) builds an alignment composed of pairs of rl columns, so omitting entries for the third column (&&) will give left alignment.

Remember to say

\usepackage{amsmath}


in your preamble and to put the relation symbol where the alignment should be after the & separating the right aligned column from the left aligned one.

-
It is also possible to use mathtools instead of amsmath, because they load amsmath internally but providing even more power of math typing than amsmath –  Tobi Apr 6 '12 at 11:02
@Tobi: In the present case, what might the mathtools macros and environments provide for the OP's question that can't be accomplished equally well with the align* environment provided by the amsmath package? Would the syntax become easier? –  Mico Apr 6 '12 at 16:33
The syntax would be the same since it’s the definitions of amsmath working here. But mathtools has some more features and I wanted to mention it here … –  Tobi Apr 6 '12 at 17:18