[Tex/LaTex] Specify dimensions of block matrices in Latex

matrices

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 🙂

Best Answer

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

enter image description here

\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.