Edit: I swapped \begin{aligned} &\ro{r_2+-1r_1}\\ &\end{aligned}
with &\ro{r_2+-1r_1}\\
, added some linebreaks an now it looks quite well.
I am working on a python matrix editor(it's still WIP) which outputs matrix equations as LaTex. In this case I tried to calculate an inverse matrix. The matrices should align beneath one another, but the line continues beyond the document.
I also tried adding linebreaks(\\
and\newline
) but it didn't turn out as I hoped.
I want it to look something like this but better aligned.(This format doesn't always work, and causes a huge amount of warning/error messages)
\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}
I'm still very new to LaTex and don't really know much about formating... I hope you can help me.
\begin{aligned} &\ro{r_2+-1r_1}\\ &\end{aligned}
a single row, single column alignment can't do anything useful?+-
inr_2+-1r_1
and other places denote? "Plus/minus", maybe? If so, it would be better to write\pm
.