2

I don't know how to add labels "ABCDE" and "12345678910". And I want to set it as a matrix and not as a table. How can I achieve that?

DESIRED OUTPUT: enter image description here

\documentclass{article}
\begin{document}
\begin{table}[]
\begin{tabular}{cccccc}

        & 5 & 4 & 4 & - & \textbf{5} \\
        & - & 3 & 5 &\textbf{ 3} & 4 \\
        & 5 & 2 & - & \textbf{2} & 3 \\
        & - & \textbf{2} & 3 & 1 & 2     \\
        & 4 & - & \textbf{5} & 4 & 5     \\
        &  \textbf{5}&3  & - & 3 & 5 \\
        &3  & \textbf{2} & 3 & 2 & - \\
        &5  & \textbf{3} & 4 & - & 5 \\
        & \textbf{4} & 2 & 5 & 4 &-  \\
        &\textbf{5}  & - & 5 & 3 & 4 \\
        &  &  &  &  & 
    \end{tabular}
\end{table}

\end{document}

enter image description here

1
  • 2
    \bordermatrix should do what you want. Jul 9 '19 at 17:52
3

No need for a hammersledge like tikz for that: blkarray does it easily:

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{blkarray}
\usepackage[svgnames]{xcolor}

\begin{document}

\[ \mathbf{R }= \begin{blockarray}{r*{5}{ >{\color{LightSalmon}}c}}
& A & B & C & D & E \\
\begin{block}{ >{\scriptstyle}r!{\,}(ccccc)}
1 & 5 & 4 & 4 & - & \mathbf{5} \\
2 & - & 3 & 5 &\mathbf{ 3} & 4 \\
3 & 5 & 2 & - & \mathbf{2} & 3 \\
4 & - & \mathbf{2} & 3 & 1 & 2 \\
5 & 4 & - & \mathbf{5} & 4 & 5 \\
6 & \mathbf{5}&3 & - & 3 & 5 \\
7 & 3 & \mathbf{2} & 3 & 2 & - \\
8 & 5 & \mathbf{3} & 4 & - & 5 \\
9 & \mathbf{4} & 2 & 5 & 4 &-  \\
10 & \mathbf{5} & - & 5 & 3 & 4 \\
\end{block}
\end{blockarray} \]%

\end{document} 

enter image description here

3
  • your solution is nice! but TikZ is not hammersledge IMO
    – Black Mild
    Aug 23 '19 at 11:40
  • With a documentation of 1302 pages?
    – Bernard
    Aug 23 '19 at 11:42
  • 1
    1302-page TikZ manual is simply the best guide for a package. I got TikZ, so I draw almost everything, I can ignore many other package, I save my memory.
    – Black Mild
    Aug 23 '19 at 13:57
4

With {pNiceMatrix} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\begin{table}[tbp]
$\mathbf{R} = 
\begin{pNiceMatrix}%
 [first-col,
  first-row,
  code-for-first-col = \color{blue},
  code-for-first-row = \color{blue}]
& A & B & C & D & E     \\
1 &  5 & 4 & 4 & - & \mathbf{5} \\
2 &  - & 3 & 5 &\mathbf{ 3} & 4 \\
3 &  5 & 2 & - & \mathbf{2} & 3 \\
4 &  - & \mathbf{2} & 3 & 1 & 2 \\
5 &  4 & - & \mathbf{5} & 4 & 5 \\
6 & \mathbf{5}&3  & - & 3 & 5 \\
7 & 3  & \mathbf{2} & 3 & 2 & - \\
8 & 5  & \mathbf{3} & 4 & - & 5 \\
9 &  \mathbf{4} & 2 & 5 & 4 &-   \\
10 & \mathbf{5}  & - & 5 & 3 & 4 
\end{pNiceMatrix}$
\end{table}
\end{document}

Result of the above code

Your Answer

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