複数の行列列の列幅を等しくする

複数の行列列の列幅を等しくする

gauss環境内に次のようなマトリックスがいくつかありますalign*

\documentclass{article}
\usepackage{amsmath}
\usepackage{gauss}

\newcommand{\BAR}{%
    \hspace{-\arraycolsep}%
    \strut\vrule % the `\vrule` is as high and deep as a strut
    \hspace{-\arraycolsep}%
}

\begin{document}
\begin{align*}
= &\begin{gmatrix}[p]
1 &  0 &   1 & \BAR &  5 \\
0 &  1 & - 2 & \BAR & -2 \\
0 &  0 &   1 & \BAR &  3 \\
0 &  0 &   3 & \BAR &  9
\rowops
\add[-2]{1}{0}
\add[-4]{1}{2}
\add[-3]{1}{3}
\end{gmatrix} \\
= &\begin{gmatrix}[p]
1 &  0 &   0 & \BAR & 2 \\
0 &  1 &   0 & \BAR & 4 \\
0 &  0 &   1 & \BAR & 3 \\
0 &  0 &   0 & \BAR & 0
\rowops
\end{gmatrix}
\end{align*}
\end{document}

マトリックスは整列していますが、すべてのマトリックスの列幅を同じに保ちたいです。どうすればこれを実現できますか?

オンラインでお試しください!

答え1

\addwd[]{}幅を広げる必要がある列の任意の行に配置できるマクロを作成しました。必須引数をオプション引数の幅にします。デフォルトでは、オプション引数の幅は「-0」です。

(幅の広い列の場合の方法を示すために、2 行目の末尾の「-2」を「-25」に変更したことに注意してください)

\documentclass{article}
\usepackage{amsmath}
\usepackage{gauss}
\usepackage{calc}
\newcommand{\BAR}{%
    \hspace{-\arraycolsep}%
    \strut\vrule % the `\vrule` is as high and deep as a strut
    \hspace{-\arraycolsep}%
}
\newcommand\addwd[2][-0]{\makebox[\widthof{$#1$}]{$#2$}}
\begin{document}
\begin{align*}
= &\begin{gmatrix}[p]
1 &  0 &   1 & \BAR &  5 \\
0 &  1 & - 2 & \BAR & -25 \\
0 &  0 &   1 & \BAR &  3 \\
0 &  0 &   3 & \BAR &  9
\rowops
\add[-2]{1}{0}
\add[-4]{1}{2}
\add[-3]{1}{3}
\end{gmatrix} \\
= &\begin{gmatrix}[p]
1 &  0 &   \addwd{0} & \BAR & \addwd[-25]{2} \\
0 &  1 &   0 & \BAR & 4 \\
0 &  0 &   1 & \BAR & 3 \\
0 &  0 &   0 & \BAR & 0
\rowops
\end{gmatrix}
\end{align*}
\end{document}

ここに画像の説明を入力してください

関連情報