2

How can I label the rows with A B C D E letters instead of numbers? I tried with \alph but it did not work.

\documentclass{article}
\usepackage{xcolor}
\usepackage{blkarray, bigstrut}
\usepackage{caption}

\usepackage{amsmath}

\begin{document}

\begin{figure}[htbp]


\renewcommand{\arraystretch}{1.4}
\bigstrutjot=0.25ex \captionsetup{labelsep=none, skip=0pt}
\[ \mathbf{L}=\begin{blockarray}{r*{5}{ >{\color{black}}c}}
& A & B & C & D & E \\\noalign{\setcounter{BAenumi}{1}}
\begin{block}{ >{\scriptstyle\theBAenumi}r!{\,}[ccccc]}
         &   -   & -0.21 &   -0.41  & -0.97  & -0.75 \bigstrut[b]  \\
         & -0.21 &   -   &   -0.84  & -0.73  & 0.51   \\
         & -0.41 & -0.84 &     -    & -0.22  & -0.93   \\
         & -0.97 & -0.73 &   -0.22  &   -    &  0.068  \\
         & -0.75 & 0.51  & -0.93    & 0.068  &    -    \bigstrut[b]  \\
        \end{block}
        \end{blockarray} \]%


    \caption{Matriz de similitud Pel\'icula-Pel\'icula.}
    \label{matrizsimilitudpeliculas}
\end{figure}

\caption{}
\end{figure}

\end{document} 

enter image description here

4 Answers 4

5

With the latest version of nicematrix (v. 3.6, 2019-10-29), you can obtain the result easily:

\documentclass{standalone}
\usepackage{nicematrix}

\begin{document}

\renewcommand{\arraystretch}{1.4}

$\mathbf{L} = 
\begin{bNiceMatrix}[first-col,
                    first-row,
                    code-for-first-row = \Alph{jCol},
                    code-for-first-col = \alph{iRow}]
&  &  &  &  & \\
&   -   & -0.21 &   -0.41  & -0.97  & -0.75  \\
& -0.21 &   -   &   -0.84  & -0.73  & 0.51   \\
& -0.41 & -0.84 &     -    & -0.22  & -0.93  \\
& -0.97 & -0.73 &   -0.22  &   -    &  0.068 \\
& -0.75 & 0.51  & -0.93    & 0.068  &    -    
\end{bNiceMatrix}
$

\end{document}

Result of previous code

9
  • Could you turn it into a stand-alone document?
    – Stephen
    Oct 30, 2019 at 22:54
  • Good to know, that new version of nicematrix is available (+1). Unfortunately not yet in MikTeX distribution :-(.
    – Zarko
    Oct 31, 2019 at 5:49
  • 1
    @Delan: I have changed the code and used the class standalone (I hope I have correctly understood your comment). Oct 31, 2019 at 12:49
  • @F.Pantigny Thank you very much! Looks great!
    – Stephen
    Oct 31, 2019 at 20:38
  • 1
    @Delan, I'm to old for such change ... with small patient I will test above answer with MikTeX soon :-)
    – Zarko
    Oct 31, 2019 at 23:03
6

With an automatic writing of the first column. I also thought it was better-looking with the first row also in \scriptstyle:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{blkarray, bigstrut}
\usepackage{caption}

\usepackage{amsmath}

\begin{document}

\begin{figure}[htbp]\bigstrutjot=1ex \captionsetup{labelsep=period, labelfont=sc, skip=0pt}
    \[ \mathbf{\widehat R }= \begin{blockarray}{r*{5}{c}}
    & \scriptstyle A & \scriptstyle B & \scriptstyle C & \scriptstyle D & \scriptstyle E \\
    \noalign{\setcounter{BAenumi}{1}}
    \begin{block}{>{\scriptstyle\Alph{BAenumi}}r!{\,}[ccccc]}
    & 5 & 3.09 & 4.90 & - & \mathbf{4.62}\bigstrut[t] \\
    & - & 2.89 & 4.69 & \mathbf{3.49} & 4.42 \\
    & 4.10 & 2.19 & - & \mathbf{2.78} & 3.71 \\
    & - & \mathbf{1.00} & 2.49 & 1.29 & 2.22 \\
    & 4.90 & - & \mathbf{4.79} & 3.58 & 4.51 \\
    & \mathbf{4.88} & 2.96 & - & 3.56 & 4.48 \\
    & 3.15 & \mathbf{1.23} & 3.03 & 1.82 & - \\
    & 4.84 & \mathbf{2.92} & 4.72 & - & 4.61 \\
    & \mathbf{4.84} & 2.92 & 4.72 & 3.51 & - \\
    & \mathbf{4.61} & - & 4.49 & 3.29 & 4.22 \bigstrut[b]\\
    \end{block}
    \end{blockarray} \]%
 \caption{Matriz de similitud Película-Película.}
\label{matrizsimilitudpeliculas}
\end{figure}

\end{document} 

enter image description here

1
  • 1
    Haha it look insanely great! Thank you!!!
    – Stephen
    Oct 16, 2019 at 0:12
4

What about write this label by hand?

\documentclass{article}
%\usepackage{xcolor}
\usepackage{blkarray, bigstrut}
\usepackage{caption}

\usepackage{amsmath}

\begin{document}
\begin{figure}[htbp]
\renewcommand{\arraystretch}{1.4}
\bigstrutjot=0.25ex 
\captionsetup{skip=0pt}
\[ 
\mathbf{L} = \begin{blockarray}{r*{5}{ >{\scriptstyle}c}}
    & A & B & C & D & E \\
\begin{block}{>{\scriptstyle}r [*{5}{c}]}
      a  &   -   & -0.21 &   -0.41  & -0.97  & -0.75 \bigstrut[b]  \\
      b  & -0.21 &   -   &   -0.84  & -0.73  & 0.51   \\
      c  & -0.41 & -0.84 &     -    & -0.22  & -0.93   \\
      d  & -0.97 & -0.73 &   -0.22  &   -    &  0.068  \\
      e  & -0.75 & 0.51  & -0.93    & 0.068  &    -    \bigstrut[b]  \\
        \end{block}
        \end{blockarray} 
\]%
    \caption{Matriz de similitud Pel\'icula-Pel\'icula.}
    \label{matrizsimilitudpeliculas}
\end{figure}
\end{document}

enter image description here

3
  • The most kind Zarko, why do not use nicematrix package? :-)+1
    – Sebastiano
    Oct 16, 2019 at 9:33
  • 1
    @Sebastiano, i estimate that it is (i) overkill option, and (ii) temporary it not works to me (see my question tex.stackexchange.com/questions/511947/…).
    – Zarko
    Oct 16, 2019 at 9:48
  • I have seen your question and I have know that the maintener of the package I have read also.
    – Sebastiano
    Oct 16, 2019 at 14:34
0

Using spalign package:

\documentclass{article}
\usepackage{amsmath}
\usepackage{spalign}
\begin{document}
\[ \mathbf{L}=\def\spalignendline{\cr}
\spalignrun{\bordermatrix{\the\spaligntoks}}
{, A B C D E ; a - -0.21 -0.41 -0.97 -0.75; b -0.21 - -0.84 -0.73 0.51 ; c -0.41 -0.84 - -0.22 -0.93; d -0.97 -0.73 -0.22 - 0.068; e -0.75 0.51 -0.93 0.068 -;} \]
\end{document}

enter image description here

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.