user875234
user875234

Reputation: 2517

How do you align a system of equations when one line is longer than the others?

I'm trying to align this system of equations nicely but it doesn't work out. I think I could hack it but I keep running into this problem and would like to do it right. fiddle

enter image description here

\begin{align}
    a_{11}x_1  + a_{12}x_2  + a_{13}x_3 + \cdots + a_{1n}x_n &= 0 \\
    a_{21}x_1  + a_{22}x_2  + a_{23}x_3 + \cdots + a_{2n}x_n &= 0 \\
    a_{31}x_1  + a_{32}x_2  + a_{33}x_3 + \cdots + a_{3n}x_n &= 0 \\
    &\vdots \\
    a_{m1}x_1  + a_{m2}x_2  + a_{m3}x_3 + \cdots + a_{mn}x_n &= 0
\end{align}

Upvotes: 4

Views: 2804

Answers (2)

Werner
Werner

Reputation: 15065

You can set this in a single align and adjust for the spacing using some \phantoms and overlapping:

enter image description here

\begin{align}
  \phantom{a_{m1}x_1}\llap{a_{11}x_1\,} + 
    \phantom{a_{m2}x_2}\llap{a_{12}x_2\,} + 
    \phantom{a_{m3}x_3}\llap{a_{13}x_3\,} + \cdots + 
    \phantom{a_{mn}x_n}\llap{a_{1n}x_n\,} &= 0 \\
  \phantom{a_{m1}x_1}\llap{a_{21}x_1\,} + 
    \phantom{a_{m2}x_2}\llap{a_{22}x_2\,} + 
    \phantom{a_{m3}x_3}\llap{a_{23}x_3\,} + \cdots + 
    \phantom{a_{mn}x_n}\llap{a_{2n}x_n\,} &= 0 \\
  \phantom{a_{m1}x_1}\llap{a_{31}x_1\,} + 
    \phantom{a_{m2}x_2}\llap{a_{32}x_2\,} + 
    \phantom{a_{m3}x_3}\llap{a_{33}x_3\,} + \cdots + 
    \phantom{a_{mn}x_n}\llap{a_{3n}x_n\,} &= 0 \\
  & \phantom{{}={}}\llap{\vdots~~} \\
  a_{m1}x_1 + a_{m2}x_2 + a_{m3}x_3 + \cdots + a_{mn}x_n &= 0
\end{align}

Fiddle

\phantom{<stuff>} sets <stuff> in an invisible box thereby taking up the space of <stuff> (horizontally and vertically) without setting anything visually. \llap{<stuff>} puts <stuff> in a zero-width box that is right-aligned. This effectively lets <stuff> hang or overlap to the left.

Additional alignment tweaks are made possible by \, - a small horizontal space.

Upvotes: 4

Heinrich
Heinrich

Reputation: 820

In align and similar environments, vertical alignment is performed along the & characters in each line. So, if you want to align along each + sign, equip them with & each:

EDIT: Since align centers the rows, you need to surround the + with & on both sides:

\begin{align}
    a_{11}x_1  &+& a_{12}x_2  &+& a_{13}x_3 &+& \cdots &+& a_{1n}x_n &=& 0 \\
    a_{21}x_1  &+& a_{22}x_2  &+& a_{23}x_3 &+& \cdots &+& a_{2n}x_n &=& 0 \\
    a_{31}x_1  &+& a_{32}x_2  &+& a_{33}x_3 &+& \cdots &+& a_{3n}x_n &=& 0 \\
    &&&&&&&&&\vdots \\
    a_{m1}x_1  &+& a_{m2}x_2  &+& a_{m3}x_3 &+& \cdots &+& a_{mn}x_n &=& 0
\end{align}

Alternatively, you could use \[\begin{array}{lllll}...\end{array}\] as an environment, left-aligning the individual columns.

Upvotes: 1

Related Questions