Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm creating a system of equations in LaTeX, using a cases environment, with variables $x_1$, $x_2$, $x_3$ and $x_4$. Here's my MWE:

\documentclass[a4paper,12pt,onecolumn]{article}

\usepackage{amsmath}

\begin{document}
    \begin{math}
        \begin{cases}
             x_1 +  x_2 + x_3 +  x_4 =  3\\
                 - 3x_2 + x_3 - 2x_4 = -3\\
                         2x_3 + 5x_4 = -3\\
                              - 7x_4 = -7
        \end{cases}
    \end{math}
\end{document}

I would like to keep the variables vertically aligned in the output, as they appear in the source code above. How can I do that?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

The cases environment is probably not the best tool for your purpose. You may instead want to look into using the systeme package and the associated macro \systeme.

The following example illustrates the usage of this macro. The only manual adjustment I've applied is for the RHS term in the first equation, where I've added a \phantom{-} term to adjust the alignment.

enter image description here

\documentclass[a4paper,12pt,onecolumn]{article}
\usepackage{systeme}
\begin{document}
\begin{math}
\systeme{
x_1 +  x_2 + x_3 +  x_4 =  \phantom{-}3,
- 3x_2 + x_3 - 2x_4 = -3,
2x_3 + 5x_4 = -3,
- 7x_4 = -7}
\end{math}
\end{document}

Addendum: The preceding look could actually be achieved via a cases environment, as follows:

\begin{math}
\begin{cases}
\hfill x_1 + \phantom{2}x_2 + \phantom{2}x_3 + \phantom{2}x_4 = \phantom{-}3\\
\hfill {}- 3x_2 + \phantom{2}x_3 - 2x_4 = -3\\
\hfill 2x_3 + 5x_4 = -3\\
\hfill {}- 7x_4 = -7
\end{cases}
\end{math}

However, compared with the work required when using the systeme package, four \hfillinstructions, three extra \phantom instructions, and two {} empty groups are required to get the job done. I guess everyone will agree that systeme is the much better tool for this job...

share|improve this answer
2  
I never knew of the system package. Would be nice to have the manual in english! –  DJJerome Dec 28 '13 at 21:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.