# Alignment in math equations

How can I align my equations as in the image below?

I know

$$\begin{split} x_1'(t) &= x_1(t)+2 x_2(t) \\ x_2'(t) &= 3 x_1(t) \end{split}$$


but it will only align the equal signs and not the variables.

-
Please make your code compilable (if possible), or at least complete it with \documentclass{...}, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. –  Jubobs Dec 8 '13 at 19:05
Why? These is not much reason to align more than one place in this set of equations –  daleif Dec 8 '13 at 19:19
Very similar to tex.stackexchange.com/q/35174/15925 –  Andrew Swann Dec 8 '13 at 19:48
@AndrewSwann - The \systeme approach mentioned in one of the answers in your link won't work in the present case, as it'll insist on placing the variables x_1'(t) and x_2'(t) in different columns... –  Mico Dec 8 '13 at 20:22

You can use

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{alignat*}{3}
x_1'(t) &=  &x_1(t) &{}+{}& 2&x_2(t)\\
x_2'(t) &= 3&x_1(t) &     &  &
\end{alignat*}

\end{document}


Notice that I have added three alignment points in case you need to vertically align the second factor on the right-hand side too.

I hope it's clear how to extend this is more than three alignment points. (Fore n alignment points, 2n-1 &'s are needed.)

P.S. Remember the use of {} to get the correct spacing.

Update

In case you don't need more than two alignment points, you can use the following:

\begin{alignat*}{2}
x_1'(t) &={}&  &x_1(t) + 2x_2(t)\\
x_2'(t) &={}& 3&x_1(t)
\end{alignat*}

-
In alignat, the columns are alternately right and left aligned. With the first example, the coefficients are left aligned and the variables are right aligned. This looks bad when coefficients have different numbers of digits, or if the x_1(t) needs to align with x_1(2t). In the second example, the extra & makes for better alignment in such cases. –  Dan Dec 9 '13 at 2:54
@Dan Thanks. I've updated my answer. –  Svend Tveskæg Dec 9 '13 at 14:08

Simple array:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$$% \begin{split} \begin{array}{r@{\;}r@{}l} x_1'(t) =& x_1(t)&{}+2 x_2(t) \\ x_2'(t) =& 3 x_1(t)& % \end{split} \end{array}$$
\end{document}


Probably vertical spacing needs some correction by adding a suitable length after \\. BTW: one can induce that an image in your example is an effect of just array, but without the correction of \arraycolsep. The spacing around + and = signs is too big.

-

Especially if your system of equations is fairly small -- as is the case with the example you've posted -- you could simply use \phantom directives: They insert whitespace equivalent to their arguments. (However, if the system of equations gets larger, it may be worth incurring the overhead associated with the other proposed methods.)

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$$\begin{split} x_1'(t) &= \phantom{3}x_1(t)+2 x_2(t) \\ x_2'(t) &= 3 x_1(t) \end{split}$$
\end{document}

-