6

I want to make horizontal and vertical curly braces to show up simultaneously just outside a matrix, but it only works when I use one or the other, instead of both.

I use \left.\right\} for vertical braces, and \underbrace{}_{} for horizontal ones.

Here's my attempt:

\begin{align*}
    \underset{m\times n}{0}=
    \underbrace{\left.
    \begin{bmatrix}
        0 & 0 & \dots & 0\\
        0 & 0 & \dots & 0\\
        \dots & \dots & \dots & \dots\\
        0 & 0 & \dots & 0
    \end{bmatrix}
    \right\}\text{$m$ rows}}_\text{$n$ columns}
\end{align*}

Enter image description here

Obviously, the "n columns" one is too long: I want it to cover from the first element to the last, not all the way to the end of the vertical brace. How can I fix it?

1

2 Answers 2

8

I wouldn't be so fussy about showing the definition of a zero matrix like that, but you know your students…

\documentclass{article}
\usepackage{amsmath}

\usepackage{lipsum} % for mock text

\begin{document}

\lipsum[1][1-4]
\begin{equation*}
% a disposable command for avoiding repetitions
\newcommand{\zm}{%
  \begin{bmatrix}
    0 & 0 & \dots & 0\\
    0 & 0 & \dots & 0\\
    \vdots & \vdots & \ddots & \vdots\\
    0 & 0 & \dots & 0
  \end{bmatrix}%
}
\underset{m\times n}{0}=
  \left.
  \,\smash[b]{\underbrace{\!\zm\!}_{\textstyle\text{$n$ columns}}}\,
  \right\}\text{$m$ rows}
  \vphantom{\underbrace{\zm}_{\text{$n$ columns}}}
\end{equation*}
\lipsum[1][1-3]

\end{document}

The trick is to pretend that the \underbrace part does not really extend below the baseline, so \right\} will just take care of the upper part, but it acts symmetrically around the formula axis.

A \vphantom makes the formula with the right depth so not to destroy the spacing with the following material.

I applied \, and \! to avoid the underbrace being too wide and collide with the right brace.

Don't use align for single displayed formulas.

enter image description here

3
  • Thanks! Just as a side question, what would you do to show the definition of a zero matrix?
    – CELLSecret
    May 18, 2022 at 22:13
  • 1
    @CELLSecret A matrix with the appropriate shape with all zero entries.
    – egreg
    May 18, 2022 at 22:40
  • Gotcha. (accepted)
    – CELLSecret
    May 18, 2022 at 23:07
7

Here is a solution with {bNiceMatrix} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

$\underset{m \times n}{0} = 
\begin{bNiceMatrix}
0 & 0 & \ldots & 0 \\
0 & 0 & \ldots & 0 \\
\vdots & \vdots & \ddots & \vdots \\
0 & 0 & \ldots & 0 
\CodeAfter
  \UnderBrace[yshift=2mm]{4-1}{4-4}{n \text{ columns}}
  \SubMatrix{.}{1-1}{4-4}{\}}[xshift=2mm]
\end{bNiceMatrix}$\quad
$m$ rows

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

1
  • Thanks for the suggestion! That looks pretty good :) (+1; sorry, I can only accept one answer)
    – CELLSecret
    May 18, 2022 at 23:08

You must log in to answer this question.

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