7

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.

  • 1
    Please provide a MWE next time. Furthermore, what packages do you have installed now? – Svend Tveskæg Mar 14 '13 at 13:03
11

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

| improve this answer | |
  • This is the easiest and elegant way I've seen to do it. Thanks alot. But how about vertical braces and down face braces. I really appreciate if you can provide these features. – CroCo Feb 12 '15 at 19:24
  • This only produces nice results if all matrix entries have the same width. If one replaces the first zero with x+y+z the result looks really ugly. – Hyperplane Dec 6 '19 at 10:58
5

Your code was not a minimal working example (MWE) (It's missing \begin{document} and \end{document}. Please make it a habit to provide one.

You should really consider using the \tikzmark macro for this. There are already a lot of answers regarding this tikz-based macro on this site. (AFAIK, a package is on the way to completion based on this macro by Andrew Stacey. For instance you can read the related question: \underbrace at a strange place, spanning array columns which you can tailor to the code below:

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture,baseline=(#1.base)]
  \node (#1) {\strut};}
\begin{document}
\[
\left (
\begin{array}{rrr|rrr}
0 & 0 & 0 &\tikzmark{upper1} 0 & 0 & 0\tikzmark{upper2} \\
0 & 0 & 0 & 0 & 0 & 0 \\
\tikzmark{lower1}0 & 0 & 0\tikzmark{lower2} & 0 & 0 & 0 \\
\end{array}
\right )
\]

\begin{tikzpicture}[overlay, remember picture,decoration={brace,amplitude=5pt}]
\draw[decorate,thick] (lower2.south) -- (lower1.south)
      node [midway,below=5pt] {Left block};
\draw[decorate,thick] (upper1.north) -- (upper2.north)
      node [midway,above=5pt] {Right block};
\end{tikzpicture}
\end{document}

enter image description here

You have to compile this twice to see the same output.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.