0

How to create two matrix one on top of the other in a similar way done here?

The problem of the proposed solution is that only one column matrix are allowed.

Here my code:

\begin{equation}
    \Gamma =
    \begin{matrix}
        { } \\
        AB \\
        AC \\
        CC \\
        BD \\
        CD
    \end{matrix}
    \begin{matrix}
    A & B & C & D \\
    \begin{bmatrix}
        3 & -1 & 0 & 0 \\
        1 & 0 & -1 & 0 \\
        0 & 0 & 0 & 0 \\
        0 & 2 & 0 & -3 \\
        0 & 0 & 4 & -2
    \end{bmatrix}
    \end{matrix}
\label{eq:networkMatrix}
\end{equation}

Which gives me this result:

enter image description here

I would like to have A, B, C, and D aligned with the column. Any suggestion? Please note that I would like to continue to use equation so align is not allowed within it. Also, the use of nicematrix is not possible. Following the problem in details:

When using nicematrix the error prompt is:

Environment bNiceArray undefined. \begin{bNiceArray}
[...]
Misplaced alignment tab character &. &
[...]

Looking here and here, it seems that the problem can be the version of Latex I am using. So:

$ sudo apt-get install texstudio
...
texstudio is already the newest version (2.12.6+debian-2).
...

and

$ sudo apt-get install texlive-full
...
texlive-full is already the newest version (2017.20180305-1).
...

And, if I try to manually install the program from the official website here, this is the result: Unable to install TexStudio and No software repo included.

enter image description here

The reason for this is here explained.

The conclusion is that I cannot use nicematrix on this workstation until I do not change OS.

@F.Pantigny, does this information match with yours? Do I need the newst TeXstudio version to use nicematrix? I think I will move this question to a new one.

Leos313
  • 639

2 Answers2

4

You might be interested in nicematrix.

\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\[\Gamma= 
\begin{bNiceArray}{cccc}[first-row,first-col]
 & A & B & C & D \\
 AB &3 & -1 & 0 & 0 \\
 AC& 1 & 0 & -1 & 0 \\
 CC& 0 & 0 & 0 & 0 \\
 BD& 0 & 2 & 0 & -3 \\
 CD& 0 & 0 & 4 & -2\\
\end{bNiceArray}
\]
\end{document}

enter image description here

F. Pantigny
  • 40,250
  • thank but absolutely not. It breaks a lot (a lot, believe me) of code everywhere in the book. However, it can be a solution for someone else but not for me. Thank you (i have already the same code working in a separate latex project) :) – Leos313 Apr 30 '20 at 16:49
  • and, in any case, +1 :) – Leos313 Apr 30 '20 at 16:55
  • 5
    @Leos313: I'm the author ot the package nicematrix. I'm interested to know which code is broken by the use of nicematrix (except in the case of the option renew-matrix). – F. Pantigny Apr 30 '20 at 16:58
  • in this case, I will try to give you more details asap – Leos313 Apr 30 '20 at 17:01
  • @Leos313, so far I haven't any bad experiences with use nicematrix. You only need to compile your document twice. – Zarko Apr 30 '20 at 17:01
  • @Leos313 There might be potentially problems depending on the other packages you load (but if you have an up-to-date TeX installation this might be avoidable). Please do not get me wrong, but this is the reason why so many users insist on a minimal working example. Then those who write an answer can test if the answer works for the OP. (But I'd also be interested to see what one needs to do to make nicematrix not work.) –  Apr 30 '20 at 17:07
  • @F.Pantigny, ok, I can confirm that the code above works properly if I use it in Overleaf. When I use Texstudio (v2.12.6 on Xubuntu 18.10) to compile the same, the first error message prompted is Environment bNiceArray undefined. \begin{bNiceArray}. All the others are similar to Misplaced alignment tab character &. &. I have tried to update versions of Texstudio but, the XUbuntu package editor says Texstudio is already the newest version (2.12.6+debian-2). I think the problem is not due to the other packages I am using. Did you face a problem like that before? – Leos313 Apr 30 '20 at 17:58
  • @Leos313 May it be that TeXStudio is an editor but you really want to update your TeX installation? –  Apr 30 '20 at 18:09
  • I did both sudo apt-get install texlive-full and sudo apt-get install texstudio. Do you mean something different from these two? – Leos313 Apr 30 '20 at 18:18
  • @Leos313 The first one should do. Unless you have a TeXLive installation from a previous year. (I am using a Mac, and have to switch the TeXLive installation every year, but I do not know how it is on Linux.) –  Apr 30 '20 at 18:22
  • My computer says: texlive-full is already the newest version (2017.20180305-1). It is an old one. This should be the problem. May I should change the OS? that's crazy ( https://askubuntu.com/questions/151283/why-dont-the-ubuntu-repositories-have-the-latest-versions-of-software ). Finally the problem should be this one. – Leos313 Apr 30 '20 at 18:27
  • @Leos313 I do not think you have to change the OS. Also on a Mac I have to install a new TeXLive version every year (and dump the older one). So you probably only need to install a 2020 version from here. –  Apr 30 '20 at 18:29
  • I have added all the information collected and update the question (as I promised to @F.Pantigny ). I think now the issue is with the use of nicematrix. So, as soon as I have a bit of time, I will move the question to a new one. – Leos313 May 01 '20 at 10:04
0

Some progress can be made using arrays and a bit of fine tuning. Not an ideal solution, but given some of the constraints it seems palatable.

enter image description here

\documentclass{extarticle}

\usepackage{amsmath,array}
\usepackage{multicol}
\usepackage{ragged2e}

\newlength{\rowwidth}
\setlength{\rowwidth}{1.2em}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\begin{equation}
\Gamma =
\begin{matrix}
{ } \\
AB \\
AC \\
CC \\
BD \\
CD
\end{matrix} 
\begin{array}{l}
\hphantom{\left[\right.\,}%
\begin{array}{C{\rowwidth}C{\rowwidth}C{\rowwidth}C{\rowwidth}}
A & B & C & D \\
\end{array} \\
\left[\begin{array}{C{\rowwidth}C{\rowwidth}C{\rowwidth}C{\rowwidth}}
3 & -1 & 0 & 0 \\
1 & 0 & -1 & 0 \\
0 & 0 & 0 & 0 \\
0 & 2 & 0 & -3 \\
0 & 0 & 4 & -2 
\end{array}\right]
\end{array}
\end{equation}

\end{document}
oliversm
  • 2,717