# Math Help - System of Linear Equations

1. ## System of Linear Equations

I am interested in typesetting a system of linear equations in a manner demonstrated below. I'm having quite a bit of trouble getting everything to line up. Any suggestions would be appreciated!

2. Hello,
interesting question. I know how to get the equations lined up on the "equals" sign, but I never tried to line up every term to a respective position. It doesn't work by using the & symbol repeatedly. Perhaps looking into the array environment, but this would be quite limited and ugly I guess. I'll browse the internet.

By the way, did you know it was possible to draw a smooth bracket in front of the system (so as to say it is a system), as follows :

Code:
\left \{ the system \right.

3. Originally Posted by roninpro
I am interested in typesetting a system of linear equations in a manner demonstrated below. I'm having quite a bit of trouble getting everything to line up. Any suggestions would be appreciated!
If I understand you, then you can try putting 0 just in front of the missing variables (e.g. $0x_{1}$) and the number 2

4. Yeah but that would be kind of limited and not exactly good looking would it ? Furthermore what if some variable has a two-digit coefficient in front of it, would you put 00 in front of the missing variables just to keep the alignement ? Not to mention that some numbers are larger than others ...

I'm pretty sure there is a special environment designed for this type of equations but I can't remember the name

If you are really desperate and don't have any keywords on Google you can still try looking at random mathematical papers (algebraic perhaps) and see how the authors did it in their paper by looking at the tex file ?

5. I did run a Google search before I posted this thread. I saw a few articles on the "alignat" environment, but it still wasn't quite what I wanted.

Messy stuff!

$
x_1 &+& 2x_2 &-& x_3 &\phantom{+}& \phantom{2x_4} &=& \phantom{-}2 \\
\phantom{x_1} &\phantom{+}& x_2 &-& x_3 &+& 2x_4 &=& -3 \\
-x_1 &-& 2x_2 &+& x_3 &+& x_4 &=& -3
$

Hmmm I guess it works differently in LaTeX...

7. Use an array:

\begin{array}{ccccccccccc}
&x_1&+&2x_2&-&x_3& & &=& &2\\
& & &x_2&-&x_3&+&2x_4&=&-&3\\
-&x_1&-&2x_2&+&x_3&+&x_4&=&-&3\\
\end{array}

gives:

$
\begin{array}{ccccccccccc}
&x_1&+&2x_2&-&x_3& & &=& &2\\
& & &x_2&-&x_3&+&2x_4&=&-&3\\
-&x_1&-&2x_2&+&x_3&+&x_4&=&-&3\\
\end{array}
$

CB

8. Originally Posted by CaptainBlack
Use an array:

\begin{array}{ccccccccccc}
&x_1&+&2x_2&-&x_3& & &=& &2\\
& & &x_2&-&x_3&+&2x_4&=&-&3\\
-&x_1&-&2x_2&+&x_3&+&x_4&=&-&3\\
\end{array}

gives:

$
\begin{array}{ccccccccccc}
&x_1&+&2x_2&-&x_3& & &=& &2\\
& & &x_2&-&x_3&+&2x_4&=&-&3\\
-&x_1&-&2x_2&+&x_3&+&x_4&=&-&3\\
\end{array}
$

CB
\begin{array}{cccccccccc}
\phantom{-}x_1&+&2x_2&-&x_3& & &=& \phantom{-}2\\
& &\phantom{2}x_2&-&x_3&+&2x_4&=&-3\\
-x_1&-&2x_2&+&x_3&+&\phantom{2}x_4&=&-3\\
\end{array}

looks a bit better...

$\begin{array}{cccccccccc}
\phantom{-}x_1&+&2x_2&-&x_3& & &=& \phantom{-}2\\
& &\phantom{2}x_2&-&x_3&+&2x_4&=&-3\\
-x_1&-&2x_2&+&x_3&+&\phantom{2}x_4&=&-3\\
\end{array}
$

9. Originally Posted by Prove It
\begin{array}{cccccccccc}
\phantom{-}x_1&+&2x_2&-&x_3& & &=& \phantom{-}2\\
& &\phantom{2}x_2&-&x_3&+&2x_4&=&-3\\
-x_1&-&2x_2&+&x_3&+&\phantom{2}x_4&=&-3\\
\end{array}

looks a bit better...

$\begin{array}{cccccccccc}
\phantom{-}x_1&+&2x_2&-&x_3& & &=& \phantom{-}2\\
& &\phantom{2}x_2&-&x_3&+&2x_4&=&-3\\
-x_1&-&2x_2&+&x_3&+&\phantom{2}x_4&=&-3\\
\end{array}
$
Can be done by using {crcrcrcrccl} instead of all centres, so the x's are right justified:

\begin{array}{crcrcrcrccl}
&x_1&+&2x_2&-&x_3& & &=& &2\\
& & &x_2&-&x_3&+&2x_4&=&-&3\\
-&x_1&-&2x_2&+&x_3&+&x_4&=&-&3\\
\end{array}

$\begin{array}{crcrcrcrccl}
&x_1&+&2x_2&-&x_3& & &=& &2\\
& & &x_2&-&x_3&+&2x_4&=&-&3\\
-&x_1&-&2x_2&+&x_3&+&x_4&=&-&3\\
\end{array}$

CB

10. Originally Posted by CaptainBlack
Can be done by using {crcrcrcrccl} instead of all centres, so the x's are right justified:

\begin{array}{crcrcrcrccl}
&x_1&+&2x_2&-&x_3& & &=& &2\\
& & &x_2&-&x_3&+&2x_4&=&-&3\\
-&x_1&-&2x_2&+&x_3&+&x_4&=&-&3\\
\end{array}

$\begin{array}{crcrcrcrccl}
&x_1&+&2x_2&-&x_3& & &=& &2\\
& & &x_2&-&x_3&+&2x_4&=&-&3\\
-&x_1&-&2x_2&+&x_3&+&x_4&=&-&3\\
\end{array}$

CB
What I did was move the negatives next to the numbers though...

11. Originally Posted by Prove It
What I did was move the negatives next to the numbers though...
If you want that it is trival to do (put the signs for the first volumn with the variable (and if you must delete the first c in the braces and the first & in the code)), but I wanted uniform spacing for all the terms.

CB

12. You can leave spaces in such a way as to align the various terms by using the \phantom command.

\begin{aligned}
x_1 + 2x_2 - x_3 \phantom{{}+2x_4} &= \phantom{-}2, \\
x_2 - x_3 + 2x_4 &= -3, \\
-x_1 - 2x_2 + x_3 + \phantom{2}x_4 &= -3.
\end{aligned}

\begin{aligned}
x_1 + 2x_2 - x_3 \phantom{{}+2x_4} &= \phantom{-}2, \\
x_2 - x_3 + 2x_4 &= -3, \\
-x_1 - 2x_2 + x_3 + \phantom{2}x_4 &= -3.
\end{aligned}

Edit. I see that Prove_It has already suggested using \phantom. But if you do so in the aligned environment rather than the array environment, then the spacing looks much better.