4

I am trying to make the right brace cover the whole matrix like the `\overbrace'. Is there a way to do this?

\documentclass[reqno,12pt]{amsart}
\usepackage{amsmath,mathtools,amssymb}
\usepackage[top=2cm,left=2cm,right=2cm]{geometry}
\author{something}
\title{something}

\begin{document}
\maketitle
\section{something}
 \begin{equation}
    \mathbf{G}=\overbrace{\begin{bmatrix}
    0&0&0&0&0\\
    0&0&0&0&0\\
    0.271&0&0&0&0\\
    0.498&0.271&0&0&0\\
    0.687&0.498&0.271&0&0\\
    0.845&0.687&0.498&0.271&0\\
    0.977&0.845&0.687&0.498&0.271\\
    1.087&0.977&0.845&0.687&0.498\\
    1.179&1.087&0.977&0.845&0.687\\
    1.256&1.179&1.087&0.977&0.845
    \end{bmatrix}}^{\text{something 1}} \Biggr\rbrace
  \text{something 2}
 \end{equation}
\end{document}

enter image description here

Something that works like \right\rbrace. Unfortunately you can't use \right alone. There is a workaround here tex.stackexchange.com/q/130798/156344. I would appreciate it if someone could tell me how to translate the TeX to LateX used there.

Al_Fh
  • 452
  • 1
    \left. \right\}? –  Apr 22 '19 at 15:30
  • I just need the right brace. Not the left one – Al_Fh Apr 22 '19 at 15:33
  • 1
    Yes. \left. doesn't produce anything. However, honestly this way is very bad. Consider something like https://tex.stackexchange.com/q/130798/156344 –  Apr 22 '19 at 15:34
  • I see. It looks ugly with the \left. \right. Thanks for the link. I will look into it. – Al_Fh Apr 22 '19 at 15:37
  • 1
    It is not so ugly if you use \left \right a bit more carefully. The problem is the horizontal brace. –  Apr 22 '19 at 15:38
  • I don't understand your latter question. Both answers in the linked question are in LaTeX. TeX is not related at all –  Apr 22 '19 at 16:25
  • @JouleV I see. It's just the commands. They are like the ones used in the TeXbook rather than the companion book which I am more familiar with, hence my uneducated question. I haven't have had the time to read the TeXbook yet. I'm not really sure whether it's necessary or not. – Al_Fh Apr 22 '19 at 19:42
  • 1
    The TeX commands are very different. Actually TeX is far harder. Those command are just advanced LaTeX commands –  Apr 23 '19 at 04:04

3 Answers3

4

Writing in your style:

\documentclass[reqno,12pt]{amsart}
\usepackage{amsmath,mathtools,amssymb}
\usepackage[top=2cm,left=2cm,right=2cm]{geometry}
\author{something}
\title{something}
\begin{document}
\maketitle
\section{something}
 \begin{equation}
 \newcommand\yourmatrix{\begin{bmatrix}
    0&0&0&0&0\\
    0&0&0&0&0\\
    0.271&0&0&0&0\\
    0.498&0.271&0&0&0\\
    0.687&0.498&0.271&0&0\\
    0.845&0.687&0.498&0.271&0\\
    0.977&0.845&0.687&0.498&0.271\\
    1.087&0.977&0.845&0.687&0.498\\
    1.179&1.087&0.977&0.845&0.687\\
    1.256&1.179&1.087&0.977&0.845
\end{bmatrix}}
    \mathbf{G}=\overbrace{\yourmatrix}^{\text{something 1}}\left.\vphantom{\yourmatrix}\right\}{\scriptstyle\text{something 2}}
 \end{equation}
\end{document}

In this way, the vertical brace is good, but it is a little painful to have it. The horizontal brace is not good because it groups the whole matrix (with brackets). Consider some methods used in braces over matrix and similar questions.

enter image description here


This is a good modification of it, but this is a bit overkill. Literally you can't avoid defining a macro if you follow this way.

\documentclass[varwidth]{standalone}
\usepackage{amsmath,mathtools,amssymb}
\begin{document}
 \begin{equation}
 \newcommand\yourmatrix{\begin{matrix}
    0&0&0&0&0\\
    0&0&0&0&0\\
    0.271&0&0&0&0\\
    0.498&0.271&0&0&0\\
    0.687&0.498&0.271&0&0\\
    0.845&0.687&0.498&0.271&0\\
    0.977&0.845&0.687&0.498&0.271\\
    1.087&0.977&0.845&0.687&0.498\\
    1.179&1.087&0.977&0.845&0.687\\
    1.256&1.179&1.087&0.977&0.845
\end{matrix}}
    \mathbf{G}=\left[\vphantom{\yourmatrix}\right.\overbrace{\yourmatrix}^{\text{something 1}}\left.\vphantom{\yourmatrix}\right]\left.\vphantom{\yourmatrix}\right\}{\scriptstyle\text{something 2}}
 \end{equation}
\end{document}

enter image description here


Using savebox (hope I get it right – please correct me if not)

\documentclass[varwidth]{standalone}
\usepackage{amsmath,mathtools,amssymb}
\newsavebox{\yourmatrix}
\begin{document}
 \begin{equation}
 \sbox{\yourmatrix}{$\begin{matrix}
    0&0&0&0&0\\
    0&0&0&0&0\\
    0.271&0&0&0&0\\
    0.498&0.271&0&0&0\\
    0.687&0.498&0.271&0&0\\
    0.845&0.687&0.498&0.271&0\\
    0.977&0.845&0.687&0.498&0.271\\
    1.087&0.977&0.845&0.687&0.498\\
    1.179&1.087&0.977&0.845&0.687\\
    1.256&1.179&1.087&0.977&0.845
\end{matrix}$}
    \mathbf{G}=\left[\vphantom{\usebox{\yourmatrix}}\right.\overbrace{\usebox{\yourmatrix}}^{\text{something 1}}\left.\vphantom{\usebox{\yourmatrix}}\right]\left.\vphantom{\usebox{\yourmatrix}}\right\}{\scriptstyle\text{something 2}}
 \end{equation}
\end{document}

(same output as above)

  • 2
    You could make \yourmatrix a savebox instead of a macro. – John Kormylo Apr 22 '19 at 15:46
  • @JohnKormylo Actually I read the linked question even before my attempts to answer this one. Both answers there use macros, so I am inspired :)) –  Apr 22 '19 at 15:48
  • 3
    I'd set the definition of \yourmatrix insde the equation environment itself, so it's local to the environment and not far from its usage. Having it in the preamble makes changes more awkward. This is even more necessary if you use the \sbox strategy, because math fonts might get chosen at begin document. – egreg Apr 22 '19 at 15:54
  • @egreg Yes, you are right. Localization is needed in this case, or we will need to define a hundred of different \yourmatrixs - maybe running out of name. –  Apr 22 '19 at 15:57
4

Saveboxes are basically pre-formatted text, and are therefore faster than expanding a macro. More to the point, one can extract the width, height and depth directly.

\documentclass[varwidth]{standalone}
\usepackage{amsmath,mathtools,amssymb}
\newsavebox{\yourmatrix}
\savebox{\yourmatrix}{$\begin{matrix}
    0&0&0&0&0\\
    0&0&0&0&0\\
    0.271&0&0&0&0\\
    0.498&0.271&0&0&0\\
    0.687&0.498&0.271&0&0\\
    0.845&0.687&0.498&0.271&0\\
    0.977&0.845&0.687&0.498&0.271\\
    1.087&0.977&0.845&0.687&0.498\\
    1.179&1.087&0.977&0.845&0.687\\
    1.256&1.179&1.087&0.977&0.845
\end{matrix}$}
\newcommand{\vphantombox}[1]{\vrule width0pt height\ht#1 depth\dp#1}
\begin{document}
 \begin{equation}
    \mathbf{G}=\left[\vphantombox\yourmatrix\right.\overbrace{\usebox\yourmatrix}^{\text{something 1}}\left.\vphantombox\yourmatrix\right]\left.\vphantombox\yourmatrix\right\}{\scriptstyle\text{something 2}}
 \end{equation}
\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120
3

Here is what you can do with {bNiceMatrix} of nicematrix (≥ 6.4 of 2021-11-23):

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

[ \mathbf{G} = \begin{bNiceMatrix} 0&0&0&0&0\ 0&0&0&0&0\ 0.271&0&0&0&0\ 0.498&0.271&0&0&0\ 0.687&0.498&0.271&0&0\ 0.845&0.687&0.498&0.271&0\ 0.977&0.845&0.687&0.498&0.271\ 1.087&0.977&0.845&0.687&0.498\ 1.179&1.087&0.977&0.845&0.687\ 1.256&1.179&1.087&0.977&0.845 \CodeAfter \OverBrace{1-1}{10-5}{\text{something 1}}[yshift=1mm,shorten] \SubMatrix{.}{1-1}{10-5}{}}[right-xshift=1mm,extra-height=-1mm] \end{bNiceMatrix}\quad \text{something 2}]

\end{document}

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

Output of the above code

F. Pantigny
  • 40,250