
我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”更改為“-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}