[Tex/LaTex] Underbraces in Matrix Divided in Blocks

arraysmath-modematrices

How to put underbraces, inside the parenthesis of a matrix, to name both sides of the blocks?

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{array}
\begin{document}
.
.
.
\[
\left (
\begin{array}{rrr|rrr}
0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 \\
\end{array}
\right )
\]
\end{document}

I'm compiling the code in my university server, where I can't install new packages.

Best Answer

Here's another (TikZ-free) option:

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{array}

\newcommand\undermat[2]{%
  \makebox[0pt][l]{$\smash{\underbrace{\phantom{%
    \begin{matrix}#2\end{matrix}}}_{\text{$#1$}}}$}#2}

\begin{document}

\[
\left (
\begin{array}{rrr|rrr}
0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 \\
\undermat{A}{0 & 0 & 0} & \undermat{B}{0 & 0 & 0} \\
\end{array}
\right )
\]

\end{document}

enter image description here