GeneralAligning a system of linear equations

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Plato
Posts: 6
Joined: Wed Nov 19, 2014 7:08 pm

Aligning a system of linear equations

Post by Plato »

Code: Select all

\documentclass[11pt,a4paper,openany]{report}
\usepackage{amssymb,amsmath,amsthm}
\usepackage[dutch]{babel}
\usepackage{mdframed}
\usepackage{systeme,mathtools}
\usepackage{lipsum}
\usepackage{relsize}
\newcommand\md{\ }
\renewcommand{\qedsymbol}{$\blacksquare$}
\begin{document}

\systeme{x_1=2r + s -t,x_2= r, x_3=-2s +2t, x_4=s, x_5=t}
Hello, I want to align a system of equations such that the x_1, x_2, x_3, x_4, x_5 are all underneath each other. Right now I get my system in staircase-form, like:
x_1 = 2r + s - 3t
......x_2 = r
...........x_3 = -2s + 2t
(there is empty space where the dots are) etc. I want all the x_i's aligned nicely under each other. Can someone help me with this? Thank you in advance.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Aligning a system of linear equations

Post by Johannes_B »

That is the expected behaviour of the package, try the cases-environment instead.

Code: Select all

\documentclass[11pt,a4paper,openany]{report}
\usepackage{amssymb,amsmath,amsthm}
\usepackage[dutch]{babel}
\usepackage{mdframed}
\usepackage{systeme,mathtools}
\usepackage{lipsum}
\usepackage{relsize}
\newcommand\md{\ }
\renewcommand{\qedsymbol}{$\blacksquare$}
\begin{document}

\systeme{x_1=2r + s -t,x_2= r, x_3=-2s +2t, x_4=s, x_5=t}
\[\begin{cases}x_1=2r + s -t\\x_2= r\\ x_3=-2s +2t\\ x_4=s\\ x_5=t
	\end{cases}
\]
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Aligning a system of linear equations

Post by Stefan Kottwitz »

To add to what Johannes, said, that package is for aligning terms and signs vertically, such that there's a column for each variable. That's especially good if you got several variables in each row. However, it may look a bit strange in the case of a single variable in each row when all are different. That's the case above.

As Johannes wrote, cases fits better here and is easy to write. In the current situation the terms at the left have roughly the same width. But if you got different widths, it could be good to use additional alignment. Here I change x_5 to x_{10} just as a demonstration. I used the aligned environment instead.

Code: Select all

\documentclass[11pt,a4paper,openany]{report}
\usepackage{amssymb,amsmath,amsthm}
\usepackage[dutch]{babel}
\usepackage{mdframed}
\usepackage{systeme,mathtools}
\usepackage{lipsum}
\usepackage{relsize}
\newcommand\md{\ }
\renewcommand{\qedsymbol}{$\blacksquare$}
\begin{document}
\systeme{x_1=2r + s -t,x_2= r, x_3=-2s +2t, x_4=s, x_10=t}
\[\begin{cases}x_1=2r + s -t\\x_2= r\\ x_3=-2s +2t\\ x_4=s\\ x_{10}=t
        \end{cases}
\]
\[
  \left\{\begin{aligned}
    x_1    &= 2r + s -t \\
    x_2    &= r         \\
    x_3    &= -2s + 2t  \\
    x_4    &= s         \\
    x_{10} &= t
  \end{aligned}\right.
\]
\end{document}
Stefan
LaTeX.org admin
Post Reply