# How to define the proper space between elements of a matrix?

I need to draw a simple matrix, with column corresponding to some sets. I tried the following:

$D^{4}_{2}= \left[\begin{array}{cc} \diagdown & {\begin{array}{cccccc} \{1,2\} & \{1,3\} & \{2,3\} & \{1,4\} & \{2,4\} & \{3,4\} \end{array}} \\ {\begin{array}{c} \{1,2\} \\ \{1,3\} \\ \{2,3\} \\ \{1,4\} \\ \{2,4\} \\ \{3,4\} \end{array}} & {\left(\begin{array}{cccccc} 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 & 0 & 0 \\ \end{array}\right)} \end{array}\right]$


which resulted with:

how can I space out the inner matrix elements, so it would fit the rows and columns of the entire table?

• Welcome to TeX.sx! Apr 15, 2013 at 14:11
• @StevenB.Segletes i don't have the package scalerel, and i'm googling right now on how to add a package, but since i need to distribute the lines evenly, and not like the example you linked to, isn't there a better way to do so? Apr 15, 2013 at 14:39
• Apr 15, 2013 at 14:57

Here's one possible way; \overmat writes its first argument above the entries enclosed in the second argument; the separation between columns in the inner matrix was increased using 10pt for arraycolsep:

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{xcolor}

\newcommand\overmat[2]{%
\makebox[0pt][c]{$\smash{\color{white}\overbrace{\vphantom{% \begin{matrix}{c}#2\end{matrix}}}^{\mkern12mu \text{\color{black}#1}}}$}#2}

\newcommand\diagdown{}% temporal definition

\begin{document}

$D^{4}_{2}= \left[\begin{array}{c@{}c} \diagdown & \\ {\begin{array}{>{\scriptstyle}c} \{1,2\} \\ \{1,3\} \\ \{2,3\} \\ \{1,4\} \\ \{2,4\} \\ \{3,4\} \end{array}} & \setlength\arraycolsep{10pt} {\left(\begin{array}{@{\mkern5mu}cccccc@{\mkern5mu}} \overmat{\{1,2\}}{0} & \overmat{\{1,3\}}{0} & \overmat{\{2,3\}}{0} & \overmat{\{1,4\}}{0} & \overmat{\{2,4\}}{0} & \overmat{\{3,4\}}{1} \\ 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 & 0 & 0 \\ \end{array}\right)} \end{array}\right]$

\end{document}


Since I didn't know the definition of \diagdown, I provided a partial definition \newcommand\diagdown{}. Use your actual definition in your document.

• thanks! it is exactly what i needed :) BTW, diagdown is a symbol... i didn't define anything... it's just the backslash like character in the corner... Apr 15, 2013 at 14:41

Here's a second answer using kbordermatrix - perhaps not what you want now, but a nice tool to know about. (Get kbordermatrix.sty from http://ctan.math.utah.edu/ctan/tex-archive/macros/generic/misc/kbordermatrix.sty if necessary.)

\documentclass{article}
\usepackage{amsmath}
\usepackage{kbordermatrix}
\begin{document}
\begin{equation*}
\kbordermatrix{
& \{1,2\} & \{1,3\} & \{2,3\} & \{1,4\} & \{2,4\} & \{3,4\} \\
\{1,2\} &  0 & 0 & 0 & 0 & 0 & 1 \\
\{1,3\} &  0 & 0 & 0 & 0 & 1 & 0 \\
\{2,3\} &  0 & 0 & 0 & 1 & 0 & 0 \\
\{1,4\} &  0 & 0 & 1 & 0 & 0 & 0 \\
\{2,4\} &  0 & 1 & 0 & 0 & 0 & 0 \\
\{3,4\} &  1 & 0 & 0 & 0 & 0 & 0
}
\end{equation*}
\end{document}


Here's the version using scalerel

\documentclass{article}
\usepackage{amsmath}
\usepackage{scalerel}
\begin{document}

\setlength\arraycolsep{.5ex}
\def\x{\begin{array}{c} x\\x\\x\\x\\x\\x\end{array}}

$$\begin{bmatrix} \begin{array}{c} \\ \{1,2\} \\ \{1,3\} \\ \{2,3\} \\ \{1,4\} \\ \{2,4\} \\ \{3,4\} \end{array} & \begin{array}{c} \\ \scalerel*[1.2ex]{(}{\x} \end{array} & \begin{array}{c} \{1,2\} \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 1\\ \end{array} & \begin{array}{c} \{1,3\} \\ 0 \\ 0 \\ 0 \\ 0 \\ 1 \\ 0\\ \end{array} & \begin{array}{c} \{2,3\} \\ 0 \\ 0 \\ 0 \\ 1 \\ 0 \\ 0\\ \end{array} & \begin{array}{c} \{1,4\} \\ 0 \\ 0 \\ 1 \\ 0 \\ 0 \\ 0\\ \end{array} & \begin{array}{c} \{2,4\} \\ 0 \\ 1 \\ 0 \\ 0 \\ 0 \\ 0\\ \end{array} & \begin{array}{c} \{3,4\} \\ 1 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0\\ \end{array} & \begin{array}{c} \\ \scalerel*[1.2ex]{)}{\x} \end{array} \end{bmatrix}$$

\end{document}


• Please, don't upload PDF file to imgur, because they are converted to a very low resolution PNG; prefer a PNG file that you can obtain in various ways (check the standalone class, for instance). I usually do a screen capture. Apr 15, 2013 at 15:42
• @egreg I did not intend to upload PDF, but jpg. Must have inadvertantly typed or clicked the wrong file. Thanks for the heads up. Apr 15, 2013 at 16:43