All guides

System of equations in LaTeX

Updated:

A system of equations with a brace on the left is written with the cases environment from amsmath. The same environment is used for piecewise functions; put the condition text inside \text.

Two equations

\begin{cases} x + y = 5 \\ 2x - y = 1 \end{cases}
{x+y=52x−y=1\begin{cases} x + y = 5 \\ 2x - y = 1 \end{cases}

cases draws the brace and left-aligns each row; \\ ends a row. In a full document it needs \usepackage{amsmath}.

Copying this from handwritten notes? Snap a photo of the page and CamteX turns the formulas into LaTeX. Try it free

Equals signs lined up

\left\{ \begin{aligned} 2x + y - z &= 1 \\ x - y + 2z &= 3 \\ x + y + z &= 6 \end{aligned} \right.
{2x+y−z=1x−y+2z=3x+y+z=6\left\{ \begin{aligned} 2x + y - z &= 1 \\ x - y + 2z &= 3 \\ x + y + z &= 6 \end{aligned} \right.

When the equals signs must form a column, put aligned inside \left\{ and \right. instead of using cases. \right. closes the pair with an invisible bracket.

Matrix form

\begin{pmatrix} 1 & 1 \\ 2 & -1 \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} 5 \\ 1 \end{pmatrix}
(112−1)(xy)=(51)\begin{pmatrix} 1 & 1 \\ 2 & -1 \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} 5 \\ 1 \end{pmatrix}

The same system written as matrices, ready for Cramer's rule or Gaussian elimination. Each pmatrix is its own block, placed side by side.

Piecewise function

|x| = \begin{cases} x & \text{if } x \ge 0 \\ -x & \text{if } x < 0 \end{cases}
∣x∣={xif x≥0−xif x<0|x| = \begin{cases} x & \text{if } x \ge 0 \\ -x & \text{if } x < 0 \end{cases}

The & separates each value from its condition, so all the conditions line up in a second column. \ge and \le give the greater-or-equal and less-or-equal signs.

Numbered system

\begin{equation}
  \begin{cases} x + y = 5 \\ 2x - y = 1 \end{cases}
  \label{eq:system}
\end{equation}

Wrapping cases in equation gives the whole system one number, so the text can refer to it with \eqref{eq:system}.

Common mistakes

See also

Don't want to memorize commands?

Draw a formula or paste a screenshot, and CamteX turns it into ready LaTeX.

Try it free