编辑:我将其替换\begin{aligned} &\ro{r_2+-1r_1}\\ &\end{aligned}
为&\ro{r_2+-1r_1}\\
,添加了一些换行符,现在看起来相当好。
我正在开发一个 Python 矩阵编辑器(仍在开发中),它将矩阵方程输出为 LaTex。在这种情况下,我尝试计算逆矩阵。矩阵应该彼此对齐,但线条超出了文档的范围。
我也尝试添加换行符(\\
和\newline
),但结果并不如我所愿。
我希望它看起来像这样,但排列得更好。(这种格式并不总是有效,并且会导致大量的警告/错误消息)
\documentclass{article}
\usepackage{amsmath,mathtools}
\usepackage{nicefrac}
\newenvironment{sysmatrix}[1]
{\left(\begin{array}{@{}#1@{}}}
{\end{array}\right)}
\newcommand{\ro}[1]{%
\xrightarrow{\mathmakebox[\rowidth]{#1}}%
}
\newlength{\rowidth}% row operation width
\AtBeginDocument{\setlength{\rowidth}{3em}}
\begin{document}
\begin{alignat*}{2}
\begin{sysmatrix}{rrrr|rrrr}
1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\
1 & 1 & -1 & -1 & 0 & 1 & 0 & 0 \\
1 & -1 & 1 & -1 & 0 & 0 & 1 & 0 \\
1 & -1 & -1 & 1 & 0 & 0 & 0 & 1 \\
\end{sysmatrix}
&\begin{aligned}
&\ro{r_2+-1r_1}\\
&\end{aligned}
\begin{sysmatrix}{rrrr|rrrr}
1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
1 & -1 & 1 & -1 & 0 & 0 & 1 & 0 \\
1 & -1 & -1 & 1 & 0 & 0 & 0 & 1 \\
\end{sysmatrix}
&\begin{aligned}
&\ro{r_3+-1r_1}\\
&\end{aligned}
\begin{sysmatrix}{rrrr|rrrr}
1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
1 & -1 & -1 & 1 & 0 & 0 & 0 & 1 \\
\end{sysmatrix}
&\begin{aligned}
&\ro{r_2\leftrightarrow r_3}\\
&\end{aligned}
\begin{sysmatrix}{rrrr|rrrr}
1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
1 & -1 & -1 & 1 & 0 & 0 & 0 & 1 \\
\end{sysmatrix}
&\begin{aligned}
&\ro{r_4+-1r_1}\\
&\end{aligned}
\begin{sysmatrix}{rrrr|rrrr}
1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
0 & -2 & -2 & 0 & -1 & 0 & 0 & 1 \\
\end{sysmatrix}
&\begin{aligned}
&\ro{r_4+-1r_2}\\
&\end{aligned}
\begin{sysmatrix}{rrrr|rrrr}
1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
0 & 0 & -2 & 2 & 0 & 0 & -1 & 1 \\
\end{sysmatrix}
&\begin{aligned}
&\ro{r_4+-1r_3}\\
&\end{aligned}
\begin{sysmatrix}{rrrr|rrrr}
1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
0 & 0 & 0 & 4 & 1 & -1 & -1 & 1 \\
\end{sysmatrix}
&\begin{aligned}
&\ro{r_1+1/2r_2}\\
&\end{aligned}
\begin{sysmatrix}{rrrr|rrrr}
1 & 0 & 1 & 0 & \dfrac{\strut 1}{\strut 2} & 0 & \dfrac{\strut 1}{\strut 2} & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
0 & 0 & 0 & 4 & 1 & -1 & -1 & 1 \\
\end{sysmatrix}
&\begin{aligned}
&\ro{r_1+1/2r_2}\\
&\end{aligned}
\begin{sysmatrix}{rrrr|rrrr}
1 & -1 & 1 & -1 & 0 & 0 & 1 & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
0 & 0 & 0 & 4 & 1 & -1 & -1 & 1 \\
\end{sysmatrix}
&\begin{aligned}
&\ro{r_1+1/2r_2}\\
&\end{aligned}
\begin{sysmatrix}{rrrr|rrrr}
1 & -2 & 1 & -2 & \dfrac{\strut -1}{\strut 2} & 0 & \dfrac{\strut 3}{\strut 2} & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
0 & 0 & 0 & 4 & 1 & -1 & -1 & 1 \\
\end{sysmatrix}
\end{alignat*}
\end{document}
我对 LaTex 还很陌生,对格式也不太了解...我希望你能帮助我。
答案1
简化标记,压缩数组中的空白,我还加宽了文本块。
\documentclass{article}
\usepackage{amsmath,mathtools}
\addtolength\oddsidemargin{-1cm}
\addtolength\textwidth{2cm}
\usepackage{nicefrac}
\newenvironment{sysmatrix}[1]
{\setlength\arraycolsep{3pt}
\left(\begin{array}{@{}#1@{}}}
{\end{array}\right)}
\newcommand{\ro}[1]{%
\xrightarrow{\mathmakebox[\rowidth]{#1}}%
}
\newlength{\rowidth}% row operation width
\AtBeginDocument{\setlength{\rowidth}{3em}}
\begin{document}
\begin{alignat*}{2}
&\begin{sysmatrix}{rrrr|rrrr}
1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\
1 & 1 & -1 & -1 & 0 & 1 & 0 & 0 \\
1 & -1 & 1 & -1 & 0 & 0 & 1 & 0 \\
1 & -1 & -1 & 1 & 0 & 0 & 0 & 1 \\
\end{sysmatrix}
&\ro{r_2+-1r_1}
&\begin{sysmatrix}{rrrr|rrrr}
1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
1 & -1 & 1 & -1 & 0 & 0 & 1 & 0 \\
1 & -1 & -1 & 1 & 0 & 0 & 0 & 1 \\
\end{sysmatrix}\\
\ro{r_3+-1r_1}
&\begin{sysmatrix}{rrrr|rrrr}
1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
1 & -1 & -1 & 1 & 0 & 0 & 0 & 1 \\
\end{sysmatrix}
&\ro{r_2\leftrightarrow r_3}
&\begin{sysmatrix}{rrrr|rrrr}
1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
1 & -1 & -1 & 1 & 0 & 0 & 0 & 1 \\
\end{sysmatrix}\\
\ro{r_4+-1r_1}
&\begin{sysmatrix}{rrrr|rrrr}
1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
0 & -2 & -2 & 0 & -1 & 0 & 0 & 1 \\
\end{sysmatrix}
&\ro{r_4+-1r_2}
&\begin{sysmatrix}{rrrr|rrrr}
1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
0 & 0 & -2 & 2 & 0 & 0 & -1 & 1 \\
\end{sysmatrix}\\
\ro{r_4+-1r_3}
&\begin{sysmatrix}{rrrr|rrrr}
1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
0 & 0 & 0 & 4 & 1 & -1 & -1 & 1 \\
\end{sysmatrix}
&\ro{r_1+1/2r_2}
&\begin{sysmatrix}{rrrr|rrrr}
1 & 0 & 1 & 0 & \dfrac{\strut 1}{\strut 2} & 0 & \dfrac{\strut 1}{\strut 2} & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
0 & 0 & 0 & 4 & 1 & -1 & -1 & 1 \\
\end{sysmatrix}\\
\ro{r_1+1/2r_2}
&\begin{sysmatrix}{rrrr|rrrr}
1 & -1 & 1 & -1 & 0 & 0 & 1 & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
0 & 0 & 0 & 4 & 1 & -1 & -1 & 1 \\
\end{sysmatrix}
&\ro{r_1+1/2r_2}
&\begin{sysmatrix}{rrrr|rrrr}
1 & -2 & 1 & -2 & \dfrac{\strut -1}{\strut 2} & 0 & \dfrac{\strut 3}{\strut 2} & 0 \\
0 & -2 & 0 & -2 & -1 & 0 & 1 & 0 \\
0 & 0 & -2 & -2 & -1 & 1 & 0 & 0 \\
0 & 0 & 0 & 4 & 1 & -1 & -1 & 1 \\
\end{sysmatrix}
\end{alignat*}
\end{document}