10

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
  • 1
    Please provide a MWE next time. Furthermore, what packages do you have installed now? Commented Mar 14, 2013 at 13:03

3 Answers 3

13

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

2
  • 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
    Commented Feb 12, 2015 at 19:24
  • 1
    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
    Commented Dec 6, 2019 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.

0

Here is a solution with {pNiceArray} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\[
\begin{pNiceArray}{rrr|rrr}[margin=1pt]
0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 25 & 0 \\
\CodeAfter
  \UnderBrace{3-1}{3-3}{A}[shorten]
  \UnderBrace{3-4}{3-6}{B}[shorten]
\end{pNiceArray}
\]

\end{document}

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .