How do you align a system of equations?

user875234 picture user875234 · Jan 13, 2018 · Viewed 45.6k times · Source

I want these equations to line up so that all variables and operators go straight down. I've tried a few different techniques but haven't been able to get it to work.

enter image description here

Nope:

\begin{align*}
  x+y+z=1 \\ 
  x+y+z=\frac{5}{2} \\ 
  x+y+z=5
\end{align*}

fiddle.

Answer

Andrew Swann picture Andrew Swann · Jan 15, 2018

There is a package systeme for systems of linear equations with automatic alignment of the variables and values - it even detects the variables for you.

In the standard set-up use you would just write

\begin{equation*}
  \systeme{
  x+y+z = 1,
  x+y+z = \frac{5}{2},
  x+y+z = 5
  }
\end{equation*}

Sample output

or

\begin{equation*}
  \systeme{
  3x +7z = 20,
  y - 17z = -3,
  24x + 15y = 7
  }
\end{equation*}

Second general example

which may or may not suit your taste. The bracket can removed by specifying empty delimiters by preceding the \systeme command with

\sysdelim..

(. is an empty place holder, \sysdelim needs two as it specifies a left and a right delimiter). To make the fraction bigger you can use \dfrac from the amsmath package (which you are already loading), but then you have to help with the line spacing:

Second sample

\documentclass{article}

\usepackage{amsmath,systeme}

\begin{document}

\begin{equation*}
  \systeme{
  x+y+z = 1,
  x+y+z = \frac{5}{2},
  x+y+z = 5
  }
\end{equation*}

No delimeter, displaystyle fraction and line spacing
\begin{equation*}
  \sysdelim..\systeme{
  x+y+z = 1,
  x+y+z = \dfrac{5}{2}\rule[-3ex]{0pt}{7ex},
  x+y+z = 5
  }
\end{equation*}

\end{document}

Alternatively extra spacing can be added between all lines via the command \syslineskipcoeff which is a scaling factor:

Third sample

\documentclass{article}

\usepackage{amsmath,systeme}

\begin{document}

No delimeter, displaystyle fraction and line spacing
\begin{equation*}
  \sysdelim..\syslineskipcoeff{2}\systeme{
  x+y+z = 1,
  x+y+z = \dfrac{5}{2},
  x+y+z = 5
  }
\end{equation*}

\end{document}