Aligning a system of linear equations

The command to use for this is \systeme*:

\documentclass[11pt,a4paper,openany]{report}
\usepackage{amsmath}
\usepackage{systeme}

\begin{document}

I want to figure out how I can align a system of linear equations very nicely.
At the moment I am using the following command:
\[
\systeme*{x_1=2r + s -t,x_2= r, x_3=-2s +2t, x_4=s, x_5=t}
\]

\end{document}

enter image description here

By setting the value of \syslineskipcoeff you can modify the spacing; the default value is 1.25:

\[
\syslineskipcoeff{1}
\systeme*{x_1=2r + s -t,x_2= r, x_3=-2s +2t, x_4=s, x_5=t}
\]

enter image description here


Here's a solution that uses only the array package and an array environment. In case you're curious about what's going on in the preamble of the array environment:

  • The four columns that contain variables are of type r

  • To get the correct spacing around the = symbols and the + and - signs, the amount of intercolumn whitespace (governed by the length parameter \arraycolsep) is first set to 0pt.

    • The = symbols are inserted automatically; the directive @{{}={}} tells LaTeX to treat = as an object of type mathrel.

    • The directives >{{}}c<{{}} tell LaTeX to center-set the column contents (which will be either +, -, or blank) and to treat them as objects of type mathbin.

enter image description here

\documentclass[11pt,a4paper,openany]{report}
\usepackage{array}
\begin{document}
\[
\left\{
\setlength\arraycolsep{0pt}
\begin{array}{ r @{{}={}} r  >{{}}c<{{}} r  >{{}}c<{{}}  r }
x_1 & 2r &+&  s &-&  t \\
x_2 &  r               \\
x_3 &    &-& 2s &+& 2t \\ 
x_4 &    & &  s        \\
x_5 &    & &    & &  t \\
\end{array}
\right.
\]
\end{document}

The systeme command is designed for the "matrix-like" (if you can't tell, I'm an engineer, not a mathematician) portion of the system to be on the left-hand side, not the right-hand side.

If you can accept a simple LHS->RHS swap of your input, systeme works out of the box:

\documentclass{article}
\usepackage{systeme}

\begin{document}
\systeme{2r + s -t=x_1, r=x_2, -2s +2t=x_3, s=x_4, t=x_5}
\end{document}

enter image description here

It is likely possible to create a new command in the spirit of \systeme{} with the aligned and unaligned sides reversed, but the code is above my head. ;-)