Aligning polynomial terms
You could also use the alignat*
environment from the amsmath
package- see page 5 of the documentation for details and other examples.
Note that without the {}
you don't get correct spacing after the +
sign.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{4} % 4 is the number of equation columns
x_1&+x_2& & =3\\
x_1& &{}+x_3 &= 4
\end{alignat*}
\end{document}
EDIT
Following mforbes' comment, and a few extra test cases, it is probably more robust to make extra columns for the +
and =
. For example, say that you wanted to put some coefficients in front of some of the terms.
\begin{alignat*}{4}
x_1 &{}+{}&x_2 & & &{}={}&3\\
x_1 & & &{}+{} & x_3 &{}={}&4
\end{alignat*}
As mforbes pointed out, the amsmath
documentation says 'count the maximum number of &s in any row, add 1 and divide by 2'; I've found that if you get a fraction, then you should round up, hence {4}
and not {3}
.
The systeme package easily enables such alignments:
\documentclass{minimal}
\usepackage{systeme}
\begin{document}
\sysdelim..
\systeme{x_1+x_3=6,x_2-x_3=7,x_1-x_2=4}
\end{document}
Ok, here is my final solution, thanks to everyone's suggestions and guidance. Everything is now clean and well aligned :
\begin{alignat*}
8x_1 &{}+{}& &4x_2 &{}+{}& y_1 &&&&&& &{}={}&160\\
4x_1 &{}+{}& &6x_2 && &{}+{}& y_2 &&&& &{}={}&120\\
x_1 && & && && &{}+{}& y_3 && &{}={}& 34\\
\phantom{{}+{}x_1}
&& &x_2 && && && &{}+{}& y_4 &{}={}&14
\end{alignat*}
I've split the inequalities line from the alignat
because it was messing with the columns width.
I learned:
- surround the operators in
${}+{}$
- use the exact same number of
&
on each line - use
\phantom{{}+{}x_1}
for missing terms at the head of the polynomial - don't put anything else (text) in the structure. That will mess thing up
- there are many many ways of doing the same thing and I have a lot to learn
Here's the output: