# Shrinking the size of a labeled matrix using a block array

I have created a matrix that I would like to label. However, I would like to have the labels on the smallmatrix environment rather than using an array as I have done in order to get labels into the matrix. Below I show both the labeled matrix and the size difference relative to the smallmatrix environment.

\documentclass[12pt]{article}%
\usepackage{amsmath}
\usepackage{blkarray}

\begin{document}

$\begin{blockarray}{ccccccc} & A & B & C & D & E & F \\ \begin{block}{c[cccccc]} A & 0 & 1 & 1 & 1 & 1 & 1 \\ B & 1 & 0 & 1 & 1 & 1 & 1 \\ C & 1 & 1 & 0 & 1 & 1 & 1 \\ D & 1 & 1 & 1 & 0 & 1 & 1 \\ E & 1 & 1 & 1 & 1 & 0 & 1 \\ F & 1 & 1 & 1 & 1 & 1 & 0 \\ \end{block}% \end{blockarray}%$

$\left[ \begin{smallmatrix} 0 & 1 & 1 & 1 & 1 & 1 \\ 1 & 0 & 1 & 1 & 1 & 1 \\ 1 & 1 & 0 & 1 & 1 & 1 \\ 1 & 1 & 1 & 0 & 1 & 1 \\ 1 & 1 & 1 & 1 & 0 & 1 \\ 1 & 1 & 1 & 1 & 1 & 0 \\ \end{smallmatrix}% \right]$

\end{document}


• I have since found that adding @{} in the definition of the array (ex: \begin{blockarray}{c@{}c}) reduces the horizontal distance. I am still unsure how to shrink the vertical distances though. This may also not be the most efficient way to solve this issue either. Commented Mar 15, 2018 at 16:16

This relies on the requirement that all columns in the matrix are of equal width. In addition, the value of \? (here a kern of 1.1pt) and the global kern to the header (here 9mu) might need adjustment based on the case.

This answer is based on my result here: braces over matrix

The fact that the natural width of cap letters is different than the natural width of digits allows two approaches:

1. stretch the column gap between digits

2. compress the column gap between letters

Here is approach 1:

\documentclass[12pt]{article}%
\usepackage{amsmath}
\usepackage{blkarray}
\usepackage{amsmath}
\usepackage{stackengine}
\begin{document}
$\begin{blockarray}{ccccccc} & A & B & C & D & E & F \\ \begin{block}{c[cccccc]} A & 0 & 1 & 1 & 1 & 1 & 1 \\ B & 1 & 0 & 1 & 1 & 1 & 1 \\ C & 1 & 1 & 0 & 1 & 1 & 1 \\ D & 1 & 1 & 1 & 0 & 1 & 1 \\ E & 1 & 1 & 1 & 1 & 0 & 1 \\ F & 1 & 1 & 1 & 1 & 1 & 0 \\ \end{block}% \end{blockarray}%$
\def\tmp{%
\def\?{\kern1.1pt}
\begin{smallmatrix}
\?0     \?&\? 1     \?&\? 1     \?&\? 1     \?&\? 1     \?&\? 1 \?\\
1     & 0     & 1     & 1     & 1     & 1 \\
1     & 1     & 0     & 1     & 1     & 1 \\
1     & 1     & 1     & 0     & 1     & 1 \\
1     & 1     & 1     & 1     & 0     & 1 \\
1     & 1     & 1     & 1     & 1     & 0 \\
\end{smallmatrix}
}%
\stackMath\def\stackalignment{r}% \stackon% {\begin{smallmatrix}A\\B\\C\\D\\E\\F\end{smallmatrix}\!\left[\tmp\right]}% {\stackon[1pt]{\phantom{\smash{\tmp\mkern -36mu}}}{% \begin{smallmatrix}A&B&C&D&E&F\end{smallmatrix}}\mkern 9mu}%
\end{document}


and here is approach 2:

\documentclass[12pt]{article}%
\usepackage{amsmath}
\usepackage{blkarray}
\usepackage{amsmath}
\usepackage{stackengine}
\begin{document}
$\begin{blockarray}{ccccccc} & A & B & C & D & E & F \\ \begin{block}{c[cccccc]} A & 0 & 1 & 1 & 1 & 1 & 1 \\ B & 1 & 0 & 1 & 1 & 1 & 1 \\ C & 1 & 1 & 0 & 1 & 1 & 1 \\ D & 1 & 1 & 1 & 0 & 1 & 1 \\ E & 1 & 1 & 1 & 1 & 0 & 1 \\ F & 1 & 1 & 1 & 1 & 1 & 0 \\ \end{block}% \end{blockarray}%$
\def\tmp{%
\begin{smallmatrix}
0     & 1     & 1     & 1     & 1     & 1 \\
1     & 0     & 1     & 1     & 1     & 1 \\
1     & 1     & 0     & 1     & 1     & 1 \\
1     & 1     & 1     & 0     & 1     & 1 \\
1     & 1     & 1     & 1     & 0     & 1 \\
1     & 1     & 1     & 1     & 1     & 0 \\
\end{smallmatrix}
}%
\stackMath\def\stackalignment{r}% {\def\?{\kern-1.2pt} \stackon% {\begin{smallmatrix}A\\B\\C\\D\\E\\F\end{smallmatrix}\!\left[\tmp\right]}% {\stackon[1pt]{\phantom{\smash{\tmp\mkern -36mu}}}{% \begin{smallmatrix}A\?&\?B\?&\?C\?&\?D\?&\?E\?&\?F\end{smallmatrix}}\mkern 9mu}}%
\end{document}