[Tex/LaTex] How to align elements of two matrices horizontally

aligncolumnshorizontal alignmentmatrices

I'd like to position two matrices under each other so that the columns of the matrices are rendered under each other, too. An example what I'd like to have:

  |100 200|
A=| 30  3 |
  | 1  119|

b=[ 1   0 ]

I've tried this:

\begin{align*}
    A= &\begin{vmatrix}
        100 & 200 \\
        30 & 3\\
        1 & 119
    \end{vmatrix}\\
    b= &\begin{bmatrix}
        1 & 0
    \end{bmatrix}
\end{align*}

…but it only aligns the = signs, but not the columns of the two matrices. What's the trick? Thanks in advance!

Best Answer

I assume the numbers should be right-aligned in the respective columns. If that's the case, you could

  • use {vmatrix*}[r] environments and employ suitably chosen \phantom directives to "pad" the numbers in the b row vector with invisible zeros; or

  • load the siunitx package and use its S column type inside array environments.

enter image description here

\documentclass{article}
\usepackage{mathtools}% for 'vmatrix*' and 'align*' env.
\usepackage{siunitx}  % for 'S' column type
\begin{document}
\begin{align*}
    A&= \begin{vmatrix*}[r]
        100 & 200 \\
        30 & 3\\
        1 & 119
    \end{vmatrix*}\\
    b&= \begin{vmatrix*}[r]
        \phantom{00}1 & \phantom{00}0
    \end{vmatrix*}
\end{align*}

\begin{align*}
    A&= \left\lvert 
        \begin{array}{@{}*{2}{S[table-format=3.0]}@{}}
        100 & 200 \\
        30 & 3\\
        1 & 119
        \end{array} 
        \right\rvert\\
    b&= \left\lvert 
        \begin{array}{@{}*{2}{S[table-format=3.0]}@{}}
        1 & 0
        \end{array} 
        \right\rvert
\end{align*}
\end{document}
Related Question