# How can I have a brace on the left and the top of a matrix without overlapping?

Consider the following code:

\documentclass{article}

\usepackage{amsmath}
\usepackage{rotating}

\begin{document}

\begin{align*}
\rotatebox[origin=c]{90}{$n$ parts}\left\{\overbrace{\begin{matrix}
\bullet & \bullet & \bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \cdots & \bullet\\
\bullet & \cdots & \bullet\\
\end{matrix}}^{\text{Even number}}\right.
\end{align*}

\begin{align*}
\rotatebox[origin=c]{90}{$n$ parts}\overbrace{\left\{\begin{matrix}
\bullet & \bullet & \bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \cdots & \bullet\\
\bullet & \cdots & \bullet\\
\end{matrix}\right.}^{\text{Even number}}
\end{align*}

\end{document}


This produces the following output:

In both cases, one of the braces overlaps the other. I'd like to be able to have each brace start and end exactly at one of the dots in the diagram. How can I go about accomplishing this?

• The answers to this question may be useful: tex.stackexchange.com/questions/40/… Do you need parentheses ((), [], etc) around the array of dots, or not? – alexwlchan Mar 16 '14 at 17:18
• @alexwlchan I don't need anything around the array... just a brace on the left and top so I can make a comment about the dimensions. – Mirrana Mar 16 '14 at 17:19

Here’s one way you could do it:

\documentclass{article}

\usepackage{amsmath}
\usepackage{rotating}

\begin{document}

\begin{equation*}
%
% the vertical brace
%
\rotatebox[origin=c]{90}{\scriptsize{
$n$ parts
}}
%
% an invisible matrix for height
%
\left\{\begin{matrix}
\vphantom{} \\ \vphantom{} \\ \vphantom{} \\
\vphantom{} \\ \vphantom{} \\ \vphantom{} \\
\end{matrix}\right.
%
% the horizontal brace and the visible matrix
%
\overbrace{
\begin{matrix}
\bullet & \bullet & \bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \cdots & \bullet\\
\bullet & \cdots & \bullet\\
\end{matrix}
}^{\text{
even number
}}
\end{equation*}

\end{document}


which looks like

This is very similar to your examples, with only one difference: the two braces are now wrapping around different matrices.

The matrix whose entries are all \vphantom{} doesn’t show up in the printed document, but it has the same height as the matrix of dots. If you made the dot matrix bigger or smaller, you’d need to add or remove entries from this matrix to compensate. This matrix provides the size for the vertical brace.

Then the horizontal brace wraps around the original dot matrix, and never sees the space occupied by the vertical brace.

Alternatively, here’s a fairly simple TikZ-based solution that uses the matrix library to lay out the entries, and then the decorations library to draw the braces.

\documentclass{article}

\usepackage{amsmath}
\usepackage{rotating}
\usepackage{tikz}

\usetikzlibrary{matrix, decorations.pathreplacing}

\begin{document}

\begin{tikzpicture}[decoration={brace, amplitude=6pt}]
\matrix (m) [matrix of math nodes] {
\bullet & \bullet & \bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \cdots & \bullet\\
\bullet & \cdots & \bullet\\
};
\draw [decorate, transform canvas={xshift=-0.3em}, thick]
(m-6-1.south west) -- node [left=6pt]
{\rotatebox[origin=c]{90}{\scriptsize\text{$n$ parts}}} (m-1-1.north west);
\draw [decorate, transform canvas={yshift=0.5em, xshift=0.5em}, thick]
(m-1-1.north west) -- node [above=6pt]
{\scriptsize\text{even number}} (m-1-6.north east);
\end{tikzpicture}

\end{document}


This is what the TikZ solution looks like:

• I like the tikz solution, however, it poses problems with natural positioning since tikz seems to like to position absolutely on the page. The other solution works well enough to be implemented. Thanks for the methods. – Mirrana Mar 17 '14 at 2:53

Here's how you can do it with stacks:

\documentclass{article}
\usepackage{tabstackengine}
\stackMath
\begin{document}
\setbox0=\hbox{\setstacktabbedgap{1ex}\tabbedCenterstack{
\bullet & \bullet & \bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \bullet & \bullet & \cdots & \bullet\\
\bullet & \cdots & \bullet\\
\bullet & \cdots & \bullet
}}
$\Shortstack[r]{% {\stackon{\makebox[\wd0]{\downbracefill}}{\textrm{top~text}}}\\ {\textrm{side~text}\left\{\box0\right.} }$
\end{document}