5

I've tried aligning a linear system using this code:

\[\left\{
    \begin{aligned}
        &a_{11}x_1 & + & &a_{12}x_2 & + & &a_{13}x_3 & = & &b_1 \\
        &          &   & &a_{22}x_2 & + & &a_{23}x_3 & = & &b_2 \\
        &          &   & &          &   & &a_{33}x_3 & = & &b_3
    \end{aligned}
        \right.
    \]

Everything works well, except for those two plus signs, as you can see: can someone explain me why?

enter image description here

2

6 Answers 6

6

No additional package is needed.

The root of the issue is the way the columns are align in the aligned structure: rlrlrlr ....

To synchronized the alignment two & are needed before the second + sign

a

\documentclass{article}

\usepackage{amsmath}
\begin{document}
    
    \[\left\{
    \begin{aligned}
        &a_{11}x_1 & + & &a_{12}x_2 & + & &a_{13}x_3 & = & &b_1 \\
        &          &   & &a_{22}x_2 & + & &a_{23}x_3 & = & &b_2 \\
        &          &   & &          &   & &a_{33}x_3 & = & &b_3
    \end{aligned}
    \right.
    \]
        
    
    \[\left\{
    \begin{aligned}
        &a_{11}x_1 & + & &a_{12}x_2 && + & &a_{13}x_3 & = & &b_1 \\
        &          &   & &a_{22}x_2 && + & &a_{23}x_3 & = & &b_2 \\
        &          &   & &          &&   & &a_{33}x_3 & = & &b_3
    \end{aligned}
    \right. \]

    
\end{document}

See the nice answer align is a table-like structure

2
  • The spacing around all the operators and relations are wrong/off.
    – Werner
    Apr 25 at 4:35
  • @Werner I answered the why of the question. Sandy G is the right answer. Apr 25 at 21:04
9

Depending on your desired look, you can just align once at the = signs and let the natural math spacing of LaTeX take care of the rest:

enter image description here

\[\left\{
    \begin{aligned}
       a_{11}x_1  + a_{12}x_2  + a_{13}x_3 & = b_1 \\
       a_{22}x_2  + a_{23}x_3 & = b_2 \\
       a_{33}x_3 &= b_3
    \end{aligned}
\right.\]
1
  • I didn't think about this, but you're right! Apr 23 at 10:34
3

I have worked out a solution with the array package.

\documentclass{scrarticle}

\usepackage{amsmath}
\usepackage{array}

\begin{document}
    \begin{equation*}
        \left\{
        \begin{array}{ccccccc}
            a_{11}x_{1} & + & a_{12}x_{2} & + & a_{13}x_{3} & = & b_1 \\ 
            & & a_{22}x_{2} & + & a_{23}x_{3} & = & b_2 \\
            & & & & a_{33}x_{3} & = & b_3
        \end{array}
        \right.
    \end{equation*}
\end{document}

The output looks like this array_solution If you insist on doing it with the aligned environment, this is no solution for you. But like you I often struggled with it and someone on here suggested the array package and I liked it, maybe you will too.

3

You can use alignedat instead, or \systeme.

\documentclass{article}
\usepackage{amsmath}
\usepackage{systeme}% for the second solution

\begin{document}

\[
\left\{
\begin{alignedat}{3}
  a_{11}x_1 & +{} & a_{12}x_2 & +{} & a_{13}x_3 & = b_1 \\
            &     & a_{22}x_2 & +{} & a_{23}x_3 & = b_2 \\
            &     &           &     & a_{33}x_3 & = b_3
\end{alignedat}
\right.
\]

\[
\syssubstitute{{A}{a_{11}}{B}{a_{12}}{C}{a_{13}}{D}{a_{22}}{E}{a_{23}}{F}{a_{33}}}
\systeme{
  Ax_1 + Bx_2 + Cx_3 = b_1,
         Dx_2 + Ex_3 = b_2,
                Fx_3 = b_3
}
\]

\end{document}

enter image description here

4
2

Here is a solution using the IEEEeqnarraybox environment from the IEEEtrantools (Appendix F of the documentation) package. This tutorial on typesetting equations also demonstrates the usage of the IEEEeqnarray environment.

enter image description here

\documentclass{article}

\usepackage{IEEEtrantools}

\begin{document}
\[
\left\{
\begin{IEEEeqnarraybox}[\relax][c]{;r'r'r'r'r'C'l}
a_{11}x_1 &+& a_{12}x_2 &+& a_{13}x_3 &=& b_1 \\
          & & a_{22}x_2 &+& a_{23}x_3 &=& b_2 \\
          & &           & & a_{33}x_3 &=& b_3
\IEEEstrut
\end{IEEEeqnarraybox}
\right.
\]
\end{document}

The separation between columns can be changed by using different glue types. Here I have used the ; glue (inserts 5/18em space) between the { and the 1st column and ' glue (inserts 1em space) between other columns. For other glue types, please refer to the documentation.

2

As @daleif comments, the problem could be solved easily by add a {} before & which could protect the space around symbols near &. By the way the codes could be simplified and rewritten as follows:

\[\left\{
    \begin{aligned}
        a_{11}x_1 + a_{12}x_2  + {}&a_{13}x_3  = b_1 \\
                 a_{22}x_2  + {}&a_{23}x_3  = b_2 \\
                 {}&a_{33}x_3  = b_3
    \end{aligned}
\right.\]

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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