3

I have a problem with aligning matrices with annotations on the right side. I need the annotations to show the operations I used.

To show the operations I first used the gauss package. Unfortunately the matrices do not look very good. After a couple hours of trying to fix it I found the nicematrix package, which I guess can supply the right alignment.

For both codes and examples please see below.

Questions:

  1. When using the nicematrix package, how can I insert an arrow like in the first matrix developed with gauss package?
  2. The nicematrix package has an option called "columnns-width" which you can use e. g. in a NiceMatrixBlock. When I try to translate the code I get an error saying that "NiceMatrixBlock is undefined". Without the NiceMatrixBlock (only vNiceArrayC) I did not get the error. I use Texpad with pdflatex and MacTex.

Is there a better way to solve my issue (nicely aligned matrices with annotations) than nicematrix package?

Thank you very much!

\documentclass{scrartcl}
\usepackage[utf8]{inputenc} 
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}

\usepackage{mathtools}
\usepackage{nicematrix}
\usepackage{gauss}

\begin{document}
gauss package
\begin{align*}
|A| &=  
\begin{gmatrix}[v]
0 & 0 & -5 & 4 \\
0 & -1 & 0 & 4 \\
-4 & -3 & -5 & 3 \\
1 & 1 & 0 & -1
\rowops
\swap{0}{3} 
\end{gmatrix}
\\ \\
|A| &= (-1) \cdot 
\begin{gmatrix}[v]
1 & 1 & 0 & -1 \\   
0 & -1 & 0 & 4 \\
-4 & -3 & - 5 & 3 \\
0 & 0 & -5 & 4
\rowops
\mult{2}{+ 4 \cdot \text{I}}
\end{gmatrix}
\\ \\
|A| &= (-1) \cdot
\begin{gmatrix}[v]
1 & 1 & 0 & -1 \\
0 & -1 & 0 & 4 \\
0 & 1 & -5 & -1 \\
0 & 0 & -5 & 4
\rowops
\mult{2}{+\text{II}}    
\end{gmatrix}
\\ \\
|A| &= (-1) \cdot
\begin{gmatrix}[v]
1 & 1 & 0 & -1 \\
0 & -1 & 0 & 4 \\
0 & 0 & -5 & 3 \\
0 & 0 & -5 & 4
\rowops
\mult{3}{- \text{III}}  
\end{gmatrix}
\\ \\
|A| &= (-1) \cdot
\begin{gmatrix}[v]
1 & 1 & 0 & -1 \\
0 & -1 & 0 & 4 \\
0 & 0 & -5 & 3 \\
0 & 0 & 0 & 1   
\end{gmatrix}
\\ \\
|A| &= (-1) \cdot [1\cdot(-1)\cdot(-5)\cdot1]
\\ \\
|A| &= (-1) \cdot 5
\\ \\
|A| &= -5
\end{align*}

\newpage
nicematrix package


\begin{NiceMatrixBlock}[auto-columns-width]
\begin{align*}
|A| & = 
\begin{vNiceArrayC}{CCCC}
0 & 0 & -5 & 4 & \text{change with IV}\\
0 & -1 & 0 & 4 \\
-4 & -3 & -5 & 3 \\
1 & 1 & 0 & -1 & \text{change with I}
\end{vNiceArrayC}
\\ \\
|A| &= (-1) \cdot 
\begin{vNiceArrayC}{CCCC}
1 & 1 & 0 & -1 \\   
0 & -1 & 0 & 4 \\
-4 & -3 & - 5 & 3 & |+4\cdot \text{I}\\
0 & 0 & -5 & 4
\end{vNiceArrayC}
\\ \\
|A| &= (-1) \cdot
\begin{vNiceArrayC}{CCCC}
1 & 1 & 0 & -1 \\
0 & -1 & 0 & 4 \\
0 & 1 & -5 & -1 & |+\text{II}\\
0 & 0 & -5 & 4
\end{vNiceArrayC}
\\ \\
|A| &= (-1) \cdot
\begin{vNiceArrayC}{CCCC}
1 & 1 & 0 & -1 \\
0 & -1 & 0 & 4 \\
0 & 0 & -5 & 3 \\
0 & 0 & -5 & 4 & | - \text{III}
\end{vNiceArrayC}
\\ \\
|A| &= (-1) \cdot
\begin{vNiceArrayC}{CCCC}
1 & 1 & 0 & -1 \\
0 & -1 & 0 & 4 \\
0 & 0 & -5 & 3 \\
0 & 0 & 0 & 1   
\end{vNiceArrayC}
\\ \\
|A| &= (-1) \cdot [1\cdot(-1)\cdot(-5)\cdot1]
\\ \\
|A| &= (-1) \cdot 5
\\ \\
|A| &= -5
\end{align*}
\end{NiceMatrixBlock}


\end{document}

gauss package

nicematrix package

4

with nicematrix:

\documentclass{scrartcl}
\usepackage{mathtools}
\usepackage{nicematrix}

\begin{document}

\[\setlength\arraycolsep{2pt}
\begin{aligned}
|A| & =
    \begin{vNiceArrayC}{RRRR}[name=m]
     0 &  0 & -5 &  4 & \vphantom{X}    \\
     0 & -1 &  0 &  4                   \\
    -4 & -3 & -5 &  3                   \\
     1 &  1 &  0 & -1 & \vphantom{X}
    \end{vNiceArrayC}   \\
    & = (-1){\cdot}
    \begin{vNiceArrayC}{CCCC}[columns-width=1.5em] % <--- for comparison is C columns are select
     1 &  1 &  0 & -1 \\
     0 & -1 &  0 &  4 \\
    -4 & -3 & -5 &  3 & |+4{\cdot }\mathrm{I}\\
     0 &  0 & -5 &  4
    \end{vNiceArrayC}   \\
    & = (-1){\cdot}
    \begin{vNiceArrayC}{RRRR}[columns-width=1.5em]
    1 & 1 & 0 & -1 \\
    0 & -1 & 0 & 4 \\
    0 & 1 & -5 & -1 & |+\mathrm{II}\\
    0 & 0 & -5 & 4
    \end{vNiceArrayC}   \\
    & = (-1){\cdot}
    \begin{vNiceArrayC}{RRRR}[columns-width=1.5em]
    1 &  1 &  0 & -1 \\
    0 & -1 &  0 &  4 \\
    0 &  0 & -5 &  3 \\
    0 &  0 & -5 &  4 & | - \mathrm{III}
    \end{vNiceArrayC}   \\
    & = (-1){\cdot}
    \begin{vNiceArrayC}{RRRR}[columns-width=1.5em]
    1 &  1 &  0 & -1 \\
    0 & -1 &  0 &  4 \\
    0 &  0 & -5 &  3 \\
    0 &  0 &  0 &  1
    \end{vNiceArrayC}   \\
    & = (-1){\cdot} [1{\cdot}(-1){\cdot}(-5){\cdot}1]   \\
    & = (-1){\cdot}5    \\
|A| &= -5
\end{aligned}
\]
    \begin{tikzpicture}[remember picture, overlay,name prefix =m-]
    \draw[<->] (1-5) -- ++ (4mm,0) |- (4-5);
    \end{tikzpicture}
\end{document}

enter image description here

for comparison in vNiceArrayC i use R column specifier (except in second matrix). if you more prefer numbers centered in columns (as they are in the second matrix), just replace R with C in other matrices.

to obtain final looks of equations, you need to compile document (at least) twice.

  • Thank you very much for your help. This has solved my first question. I still have a problem to load nicematrix properly. I cannot define the columns width, neither on Texpad nor on Texshop. The error message says, that the "option is unknown". Texshop also clarifies that I request version "2018-10-17" of package sparse, but only "2018-02-21 L3 Experimental version" is available. – Karl May 2 at 7:26
  • 1
    @Karl, my answer solve your both question what id concerning LaTeX, however, it seems that you have outdated nicematrix and L3. You need to update your installation, if you like to use nicematrix. in my recent miktex my solution works as shown in answer.. – Zarko May 2 at 10:29
  • I updated my distribution and now your solution works perfectly as suggested. Thank you very much! – Karl May 8 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.