1

I'm new to LaTeX and was wondering if there is a more beautiful way to have the matrices aligned than below?

Below is a sample code from the picture aboveenter image description here:

\begin{alignat*}{2}
&\!\begin{aligned}
&\ro{r_1 \rightarrow r_1 - r_2a }\\
&\ro{r_3 \rightarrow r_3 - r_2(3-a) }\\
\end{aligned}
\begin{sysmatrix}{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{sysmatrix}
&\!\begin{aligned}
&\ro{r_1 \rightarrow r_1 + r_3 }\\
\end{aligned}
\begin{sysmatrix}{rrr|r}
 1 &  0 & 2 & -\frac{a^2+4}{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{sysmatrix}
\end{alignat*}


\begin{alignat*}{2}
&\!\begin{aligned}
&\ro{r_3 \rightarrow \frac{r_3}{-2} }\\
\end{aligned}
\begin{sysmatrix}{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{sysmatrix}
\end{alignat*}


\begin{alignat*}{2}
\begin{sysmatrix}{rrr|r}
x_1\\
x_2\\
x_3
\end{sysmatrix}
&\!\begin{aligned}
&{=}\\
\end{aligned}
\begin{sysmatrix}{rrr|r}
-\frac{a^2+4}{a^2-2}  \\
\frac{a^2}{a^2-2} \\
\frac{\frac{a^2}{2}-a+2}{a^2-2}
\end{sysmatrix}
\end{alignat*}
Bernard
  • 271,350
Lubbi
  • 13

1 Answers1

3

I am not sure what your sysmatrix environment does but I would just use an align* environment for this and instead of your custom \ro command I suggest \xrightarrow, which is an arrow that expands to fit the width of the material written above (or below) it.

You have a lot of unnecessary alignat environments that can be omitted. In addition, for row operations like these I use a modification of the amsmath matrix environments that allow you to specify column alignment and add |s etc.

With this in place you can typeset your matrices as:

enter image description here

using the code:

\documentclass{article}
\usepackage{amsmath}
\makeatletter
% put line in augmented matrices (code from
% http://texblog.net/latex-archive/maths/amsmath-matrix/ )
% Example: \begin{bmatrix}[cc|c] 1&2&3\\ 2&3&1 \end{bmatrix}
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
  \hskip -\arraycolsep%
  \let\@ifnextchar\new@ifnextchar%
  \array{#1}%
}
\makeatother

\begin{document}

  \begin{align*}
    \begin{array}{r}
      \xrightarrow{r_1 \rightarrow r_1 - r_2a }\\ \\
      \xrightarrow{r_3 \rightarrow r_3 - r_2(3-a) }
    \end{array}
    \begin{pmatrix}[rrr|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{pmatrix}
   \begin{array}{r}
     \xrightarrow{r_1 \rightarrow r_1 + r_3 }\\ \\
   \end{array}
   &\begin{pmatrix}[rrr|c]
       1 &  0 & 2 & -\frac{a^2+4}{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{pmatrix}
  \\
   \begin{array}{r}\\ \\
      \xrightarrow{r_3 \rightarrow \frac{r_3}{-2} }
    \end{array}
  & \begin{pmatrix}[rrr|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{pmatrix}
  \\
  \Longrightarrow\qquad
    \begin{pmatrix} x_1\\ x_2\\ x_3 \end{pmatrix}
    =&
    \begin{pmatrix}
    -\frac{a^2+4}{a^2-2}  \\
    \frac{a^2}{a^2-2} \\
    \frac{\frac{a^2}{2}-a+2}{a^2-2}
    \end{pmatrix}
  \end{align*}

\end{document}

Note that the outer align* environment has a single alignment character & which is a the right hand matrices. In the array environments for the row operations I have put blank lines so that the row operation roughly aligns with the corresponding row.