9

I'm trying to align a system of symbolic equations with alignat command like this:

\begin{alignat}{5}
    a_{11}x_1&{}+{}a_{12}x_2&{}+{} \dots&{}+{} a_{1n}x_n&{}={}b_1\\
    a_{21}x_1&{}+{}a_{22}x_2&{}+{} \dots&{}+{} a_{2n}x_n&{}={}b_2\\
    a_{m1}x_1&{}+{}a_{m2}x_2&{}+{} \dots&{}+{} a_{mn}x_n&{}={}b_m
\end{alignat}

but the problem lies within the letter "m" in the b_m symbol. The result is as follows: enter image description here

If, however I put a number instead of "m", for ex. b_3 the result looks fine:

\begin{alignat}{5}
    a_{11}x_1&{}+{}a_{12}x_2&{}+{} \dots&{}+{} a_{1n}x_n&{}={}b_1\\
    a_{21}x_1&{}+{}a_{22}x_2&{}+{} \dots&{}+{} a_{2n}x_n&{}={}b_2\\
    a_{m1}x_1&{}+{}a_{m2}x_2&{}+{} \dots&{}+{} a_{mn}x_n&{}={}b_3
\end{alignat}

enter image description here

I would appreciate if someone can elaborate on why this happens and how to get rid of this freak occurance.

  • Probably due to the width of the m as it wants to place / center it in the column consisting of = bm, maybe 6 columns with an extra & after the = helps. – albert Aug 4 '18 at 14:02
6

alignat uses pairs columns with rl-alignment. In your example the last column is of type r. So the last column will be right aligned - see the commented line in the following code snippet:

\begin{alignat}{3}% 3 r-columns 
%         r & l              &           r & l               &        r 
  a_{11}x_1 & {}+{}a_{12}x_2 & {}+{} \dots & {}+{} a_{1n}x_n & {}={}b_1\\
  a_{21}x_1 & {}+{}a_{22}x_2 & {}+{} \dots & {}+{} a_{2n}x_n & {}={}b_2\\
  a_{m1}x_1 & {}+{}a_{m2}x_2 & {}+{} \dots & {}+{} a_{mn}x_n & {}={}b_m
\end{alignat}

Note that the argument of the alginat environment takes the numbers of r columns.

To get the desired result you have to ensure that the columns get the right alignment. In the following example there ars two suggestions with the same result:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat}{3}% 3 r-columns 
%         r & l              &           r & l               & r & l
  a_{11}x_1 & {}+{}a_{12}x_2 & {}+{} \dots & {}+{} a_{1n}x_n &   & {}={}b_1\\
  a_{21}x_1 & {}+{}a_{22}x_2 & {}+{} \dots & {}+{} a_{2n}x_n &   & {}={}b_2\\
  a_{m1}x_1 & {}+{}a_{m2}x_2 & {}+{} \dots & {}+{} a_{mn}x_n &   & {}={}b_m
\end{alignat}

\begin{alignat}{3}% 3 r-columns 
%         r & l              &           r & l               &     r & l
  a_{11}x_1 & {}+{}a_{12}x_2 & {}+{} \dots & {}+{} a_{1n}x_n & {}={} & b_1\\
  a_{21}x_1 & {}+{}a_{22}x_2 & {}+{} \dots & {}+{} a_{2n}x_n & {}={} & b_2\\
  a_{m1}x_1 & {}+{}a_{m2}x_2 & {}+{} \dots & {}+{} a_{mn}x_n & {}={} & b_m
\end{alignat}
\end{document}

enter image description here

  • Is there a way to also add vertical dots between last two lines like @egreg did in his answer? – KeVal Aug 9 '18 at 10:14
  • I found the answer. Using \vdotswithin{=} command from mathtools package does the trick! – KeVal Aug 9 '18 at 10:41
2

Based on my comment:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat}{6}
    a_{11}x_1&{}+{}a_{12}x_2&{}+{} \dots&{}+{} a_{1n}x_n&{}={}&b_1\\
    a_{21}x_1&{}+{}a_{22}x_2&{}+{} \dots&{}+{} a_{2n}x_n&{}={}&b_2\\
    a_{m1}x_1&{}+{}a_{m2}x_2&{}+{} \dots&{}+{} a_{mn}x_n&{}={}&b_m
\end{alignat}
\end{document}
2

With array:

\documentclass{article}
\usepackage{array,mathtools}

\begin{document}

\[
\renewcommand{\arraystretch}{1.5}
\setlength{\arraycolsep}{0pt}
\def\bvdots{\vdotswithin{=}}
\begin{array}{
 l l >{{}}c<{{}}   % a_{11} & x_1 & +
 l l >{{}}c<{{}}   % a_{12} & x_2 & +
 c >{{}}c<{{}}     % \cdots +
 l l >{{}}c<{{}} l % a_{12} & x_2 & = & b_1
}
  a_{11} & x_1 & + & a_{12} & x_2 & + & \cdots & + & a_{1n} & x_n & = & b_1 \\
  a_{21} & x_1 & + & a_{22} & x_2 & + & \cdots & + & a_{2n} & x_n & = & b_2 \\
         &     &   &        &     &   &        &   &        &     & \bvdots \\
  a_{m1} & x_1 & + & a_{m2} & x_2 & + & \cdots & + & a_{mn} & x_n & = & b_m
\end{array}
\]

\end{document}

enter image description here

Just for fun, with autoaligne:

\documentclass{article}
\usepackage{autoaligne}

\begin{document}

\[
\definirseparateurs{\\}{+|| }{=||V}
\endlinechar=-1
\def\bvdots{\kern-2em\vdots}
\autoaligne[*g]{
  a_{11} x_1+a_{12} x_2+\cdots+a_{1n} x_n=b_1\\
  a_{21} x_1+a_{22} x_2+\cdots+a_{2n} x_n=b_2\\
  + + + V \bvdots\\
  a_{m1} x_1+a_{m2} x_2+\cdots+a_{mn} x_n=b_m
}
\]

\end{document}

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.