# Align many matrices the best way possible?

It’s my first assignment in linear algebra and working with matrices. How would you align matrices like below the best way? Code below:

newenvironment{sysmatrix}
{left(begin{array}{@{}#[email protected]{}}}
{end{array}right)}
newcommand{ro}{%
xrightarrow{mathmakebox[rowidth]{#1}}%
}
newlength{rowidth}% row operation width
AtBeginDocument{setlength{rowidth}{4em}}

begin{equation}
begin{array}{rcl}
{
left(!!!!
begin{array}{rrr|r}
1 &  a & 2 & a \
0 &  1 & 0 & frac{-a^2}{a^2-2} \
0 & 3-a & -2 & 2-a
end{array}
!!right)
}
&
[email protected]=15ex{
ar[r]^-{small
begin{array}{r}
mathbf{r}_1 rightarrow mathbf{r}_1 - mathbf{r}_2a \
mathbf{r}_3 rightarrow mathbf{r}_3 - mathbf{r}_2(3-a) \
end{array}
} &
}
&
{
left(!!!!
begin{array}{rrr|r}
1  &  0 & 2 & -frac{2a}{a^2-2}  \
0 &  1 & 0 & frac{a^2}{a^2-2} \
0 & 0 & -2 & frac{1}{a^2-2}(-a^2+2a-4)
end{array}
!!right)
}
end{array}bigskip
end{equation}

begin{equation}
begin{array}{rcl}
{
left(!!!!
begin{array}{rrr|r}
1  &  0 & 2 & -frac{2a}{a^2-2}  \
0 &  1 & 0 & frac{a^2}{a^2-2} \
0 & 0 & -2 & frac{1}{a^2-2}(-a^2+2a-4)
end{array}
!!right)
}
&
[email protected]=16ex{
ar[r]^-{small
begin{array}{r}
mathbf{r}_1 rightarrow mathbf{r}_1 + mathbf{r}_3 \
mathbf{r}_3 rightarrow frac{mathbf{r}_3}{-2}
end{array}
} &
}
&
{
left(!!!!
begin{array}{rrr|r}
1 &  0 & 0 & -frac{a^2+4}{a^2-2}  \
0 &  1 & 0 & frac{a^2}{a^2-2} \
0 &  0 & 1 & frac{frac{a^2}{2}-a+2}{a^2-2}
end{array}
!!right)
}
end{array}
end{equation}


TeX - LaTeX Asked on November 14, 2021

Another possible solution a bit more fast using spalign package: documentclass[a4paper,12pt]{article}
usepackage[margin=2.2cm]{geometry}
usepackage{mathtools}
usepackage{spalign}

begin{document}
begin{equation}
spalignaugmat[c]{1 a 2 a; 0 1 0 dfrac{-a^2}{a^2-2}; 0 3-a -2 2-a} xrightarrow{begin{matrix}
mathbf{r}_1 rightarrow mathbf{r}_1 - mathbf{r}_2a \
mathbf{r}_3 rightarrow mathbf{r}_3 - mathbf{r}_2(3-a)
end{matrix}}{}
spalignaugmat{1 0 2 -dfrac{2a}{a^2-2}; 0 1 0 dfrac{a^2}{a^2-2}; 0 0 -2 dfrac{1}{a^2-2}(-a^2+2a-4)}
end{equation}

begin{equation}
spalignaugmat[c]{1 0 2 -dfrac{2a}{a^2-2}; 0 1 0  dfrac{a^2}{a^2-2}; 0 0 -2 dfrac{1}{a^2-2}(-a^2+2a-4)} xrightarrow{begin{matrix}
mathbf{r}_1 rightarrow mathbf{r}_1 + mathbf{r}_3 \
mathbf{r}_3 rightarrow -frac{1}{2}mathbf{r}_3
end{matrix}}{}
spalignaugmat{1 0 0 -dfrac{a^2+4}{a^2-2}; 0 1 0 dfrac{a^2}{a^2-2}; 0 0 1 dfrac{frac{a^2}{2}-a+2}{a^2-2}}
end{equation}
[mathbf{S}^{ast}=spalignaugmat[c]{1 0 0 -frac{a^2+4}{a^2-2};0 1 0 frac{a^2}{a^2-2};  0 0 1 frac{frac{a^2}{2}-a+2}{a^2-2}}]

end{document}


Answered by Sebastiano on November 14, 2021

documentclass[a4paper]{article}
usepackage[margin=2cm]{geometry}
usepackage{array}
usepackage{amsmath}
begin{document}

begin{align}
left(begin{array}{ccc|>{displaystyle}c}
1 &  a & 2 & a \
0 &  1 & 0 & frac{-a^2}{a^2-2} \
0 & 3-a & -2 & 2-a
end{array}right)
& xrightarrow{small
begin{array}{r}
mathbf{r}_1 rightarrow mathbf{r}_1 - mathbf{r}_2a \
mathbf{r}_3 rightarrow mathbf{r}_3 - mathbf{r}_2(3-a) \
end{array}}
left(begin{array}{ccc|>{displaystyle}c}
1  &  0 & 2 & -frac{2a}{a^2-2}  \
0 &  1 & 0 & frac{a^2}{a^2-2} \
0 & 0 & -2 & frac{1}{a^2-2}(-a^2+2a-4)
end{array}right)  \[10pt]
left(begin{array}{rrr|>{displaystyle}r}
1  &  0 & 2 & -frac{2a}{a^2-2}  \
0 &  1 & 0 & frac{a^2}{a^2-2} \
0 & 0 & -2 & frac{1}{a^2-2}(-a^2+2a-4)
end{array}right)
&  xrightarrow[hphantom{textstyle~mathbf{r}_3 rightarrow mathbf{r}_3 - mathbf{r}_2(3-a)}]%
{small
begin{array}{r}
mathbf{r}_1 rightarrow mathbf{r}_1 + mathbf{r}_3 \
mathbf{r}_3 rightarrow frac{mathbf{r}_3}{-2}
end{array}}
left(begin{array}{rrr|>{displaystyle}r}
1 &  0 & 0 & -frac{a^2+4}{a^2-2}  \
0 &  1 & 0 & frac{a^2}{a^2-2} \
0 &  0 & 1 & frac{frac{a^2}{2}-a+2}{a^2-2}
end{array}right)
end{align}

end{document} Answered by user187802 on November 14, 2021

## Related Questions

### Biblatex: avoid initials for specific reference

1  Asked on February 4, 2021

### Can I let Latex autobreak my algorithm?

0  Asked on February 4, 2021 by hao-s

### How can I track down the standard TeX glyphs for musical accidentals ($flat$, etc.)?

1  Asked on February 4, 2021

### Is there a program similar to detex for windows

3  Asked on February 4, 2021

### Create a book cover with spine, rear page and flaps

3  Asked on February 4, 2021

### How to draw the the following directed graph with TikZ?

1  Asked on February 4, 2021 by peize-liu

### Hyperref bookmarks for unnumbered sections

1  Asked on February 4, 2021 by mariano-surez-lvarez

### Putting video clipp at background of a slide

0  Asked on February 4, 2021 by dextoruz

### Best Way to Convert .tex to .png With Cropping & Conversion Error from PS to PNG using ImageMagick

1  Asked on February 4, 2021 by david-de-martin

### Section title above landscape tabular

1  Asked on February 3, 2021

### Acronym package: printonlyreused and capitalizing doesn’t work

0  Asked on February 3, 2021

### Problems with my ToC

1  Asked on February 3, 2021 by morten-mandsberg

### How to embed choices in tabular in exam class?

1  Asked on February 3, 2021 by e-yu

### Latex to docx conversion issues using pandoc – missing information?

0  Asked on February 3, 2021

### How to display the y-values of each bar in pgfplots bar chart above the bar?

1  Asked on February 3, 2021 by umerjamil

### 3×2 layout handout/annotations from pdf

0  Asked on February 3, 2021 by daniel-b

### Two column Paper , Graph go out side the column

1  Asked on February 3, 2021 by uma

### Decrease page margins on minipage

1  Asked on February 3, 2021 by anton-neundorfer