# Aligning a system of linear equations

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}


But this gives me something ugly in staircase form, like:

Any way I could fix it so the x_i's are all at the left side, nicely underneath each other, and possibly with the equation signs also aligned?

Here is a MWE:

\documentclass[11pt,a4paper,openany]{report}
\usepackage{amssymb,amsmath,amsthm}
\usepackage[dutch]{babel}
\usepackage{mdframed}
\usepackage{systeme,mathtools}
\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{#1}}
\makeatother
\usepackage{lipsum}
\usepackage{relsize}
\newcommand\md{\ }

\begin{document}

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

\end{document}

• normally one uses align or one of its variants from amsmath but it is impossible to comment on your code as \systeme is not a standard plain or latex command and you give no indication of its definition. Jan 4, 2015 at 23:31
• I'm using TexnicCenter, and I just use the package: \usepackage{systeme,mathtools}. There's no special definition, it's just standard. Jan 4, 2015 at 23:32
• I need to have \systeme because I want that there appears an array on the left to make it clear to the reader that it is a system of equations. Jan 4, 2015 at 23:37
• Please edit your post to show a complete, compilable document starting with \documentclass... and ending with \end{document}. That way, people will not have to spend time gradually extracting every essential detail from you, only to find they overlooked something after spending time posting an answer.
– cfr
Jan 4, 2015 at 23:39
• You have given no indication of what \systeme is, I had never heard of the command searching around suggests you are using a package of the same name and using latex, but you really should provide a complete example from \documentclass to \end{document} by editing the above question Jan 4, 2015 at 23:41

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}


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}$


• Wonderful! Appreciate it. Jan 5, 2015 at 0:08
• The letters $r, s, t$ aren't aligned. Jan 5, 2015 at 0:11
• @Bernard That's not required by the OP Jan 5, 2015 at 0:13
• @egreg: it's one of the main intrests in systeme. Else a simple align* environment would do the job. Or did I miss something? Jan 5, 2015 at 0:16
• @Bernard If one replace systeme* by systeme the letters $r, s, t$ will be aligned. Do you agree with me? Jan 13, 2021 at 10:20

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.

\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}


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. ;-)

A simple hack with the aligned environment:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{systeme}
\usepackage{amsmath}

\begin{document}

\left\{\begin{aligned}x_1 & = \\x_2 & =\\x_3 & =\\x_4 & =\\x_5 & =\\ \end{aligned}\sysdelim. . \systeme[rst]{2r + s -t , r , -2s +2t, s, t}\right.%

\end{document}


Using a TABstack. In this case the "Center" of \tabbedCenterstack refers to vertical centering, the [r] refers to horizontal right alignment of each column, \stackMath processes the data in math mode, and \TABbinary inserts a {} prior to and following each cell, so as to give the + and - the proper horizontal spacing.

\documentclass[11pt,a4paper,openany]{report}
\usepackage{tabstackengine}
\stackMath
\begin{document}
$\left\{ \TABbinary\tabbedCenterstack[r]{ x_1 =& 2r &+& s &-& t \\ x_2 =& r \\ x_3 =& &-& 2s &+& 2t \\ x_4 =& & & s \\ x_5 =& & & & & t }\right.$
\end{document}


• +1. What would you say are the main differences between using \TABbinary\tabbedCenterstack[r] and using an array environment?
– Mico
Jan 5, 2015 at 15:12
• @Mico 0pt intercolumn gap is default in tabbed... stacks; Center-stacks are long stacks, thus all lines are forced to be equal baselineskips apart (though short stacks are more akin to arrays in this regard); interrow vertical baselineskip is easily set with \setstackgap{L}{length}; more options for how to automatically treat math operators with \TABbinary, \TABbinaryRight, and \TABbinaryLeft; \fixTABwidth{T} is available to force all columns to equal width; while centerstacks are vertically centered, stacks and understacks are not, which is often very useful. Jan 5, 2015 at 15:28