TeX - LaTeX Asked by TheBaum on March 11, 2021
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(\
andnewline
) 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_2leftrightarrow 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.
Simplifying the markup, and squeezing the white space in the arrays, I also widened teh text block.
documentclass{article}
usepackage{amsmath,mathtools}
addtolengthoddsidemargin{-1cm}
addtolengthtextwidth{2cm}
usepackage{nicefrac}
newenvironment{sysmatrix}[1]
{setlengtharraycolsep{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_2leftrightarrow 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}
Correct answer by David Carlisle on March 11, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP