# Specify dimensions of block matrices in Latex

I recently started learning LaTeX and though I found answers for almost all of my questions by looking online (and especially here), there is still one more thing I would like to be able to do but can't for the article I am writing:

I would like to be able to specify the dimensions and the "subdimensions" below a matrix. To be clearer, let us take the following example:

$D = \underbracket{\begin{pmatrix} D_1 & 0 & 0 & & & \\ 0 & \ddots & & & {\textrm{\huge 0}} & \\ 0 & 0 & D_n & & & \\ & & & & & \\ & \textrm{\huge 0} & & & {\textrm{\huge 0}} & \\ & & & & & \\ \end{pmatrix}}_N$


this gives a nice matrix whith the dimension N specified as a bracket under the matrix. That is fine, however I would like to add a second bracket to specify the smaller dimension n of the inner block matrix right below the matrix (and possibly above the first main bracket) which is shorter, i.e. I would like it to extend from 1 to n and not all the way below the matrix.

I am open to any solution, but the simpler the better for me :)

-
Welcome to TeX.SE!. Do you think you can complete your code to make it a MWE, starting with \documentclass{} and ending with \end{document}, making sure you include any packages that are required to compile the above code? –  Vivi Dec 18 '12 at 3:11

The following is not really eye-candy, but it's probably what you're after:

\documentclass{article}
\usepackage{mathtools}% http://ctan.org/pkg/mathtools
\begin{document}
$D = \underbracket{\begin{pmatrix} D_1 & 0 & 0 & & & \\ 0 & \ddots & & & {\textrm{\huge 0}} & \\ 0 & 0 & D_n & & & \\ & & & & & \\ & \textrm{\huge 0} & & & {\textrm{\huge 0}} & \\ & & & & & \\ \end{pmatrix}}_N$

$D= \underbracket[.4pt]{\left(\begin{array}{@{}c@{\quad}c} \underbracket[.4pt]{\begin{array}{ccc} D_1 & \vphantom{\ddots}0 & 0 \\ 0 & \ddots & 0 \\ 0 & \vphantom{\ddots}0 & D_n \end{array}}_{n} & \text{\huge 0} \\ \\ \text{\huge 0} & \text{\huge 0} \end{array}\right)}_{N}$
\end{document}


The use of \vphantom ensure that the row height for the "inner matrix" is similar across all rows (without actually printing \ddots).

I went with a more traditional approach (using array), rather than pmatrix. The advantage is that you have control over the alignment.

-

Please always post complete documents showing all packages used. I couldn't locate underbracket. there appears to be a spurious right hand column affecting the spacing of the delimiter, also I removed some superfluous braces.

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

$D = \begin{pmatrix} D_1 & 0 & 0 & & \\ 0 & \ddots & & & \textrm{\huge 0} \\ 0 & 0 & D_n & & & \\ \multicolumn{3}{c}{$\upbracefill$}&\\ \multicolumn{3}{c}{\scriptstyle n}&\\ & & & & \\ & \textrm{\huge 0} & & & \textrm{\huge 0} \\ \multicolumn{6}{c}{$\upbracefill}\\ \multicolumn{6}{c}{\scriptstyle N}\\ \noalign{\vspace{-2\normalbaselineskip}} \end{pmatrix}\vspace{2\normalbaselineskip}

\end{document}

-
\underbracket is part of mathtools, just for the record. –  Max Dec 18 '12 at 5:26
@DavidCarlisle -- your result, while "accurate", is unappealingly uneven. i added another answer with some prettifying that you're welcome to incorporate if you like; i would have just commented, but the code would have been undecipherable in a comment. (well, maybe not for you ...) –  barbara beeton Dec 18 '12 at 17:28

this is really the same as david's answer, but is prettied up a bit:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
D = \begin{pmatrix} \;D_1 & 0 & 0 & & & \\[-.5ex] 0 & \clap{\ddots} & & & \raisebox{-1ex}{\huge 0} & \strut\enspace \\[4pt] 0 & 0 & D_n & & & \\ \multicolumn{3}{c}{\upbracefill}&\\ \multicolumn{3}{c}{\scriptstyle n}&\\ & & & & \\ & \textrm{\huge 0} & & & \textrm{\huge 0} & \\ \multicolumn{6}{c}{\upbracefill}\\ \multicolumn{6}{c}{\scriptstyle N}\\ \noalign{\vspace{-2\normalbaselineskip}} \end{pmatrix} \vspace{2\normalbaselineskip}
\end{document}

-
+1 for making me pretty –  David Carlisle Dec 18 '12 at 17:34