1

I want to generate something like in the figure below. I have currently the following but is not complete as you can observe. Any idea how to do this?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mleftright}
\usepackage{mathtools}

\begin{document}

\begin{align} \overbrace{ \mleft[ \begin{array} \mat{A}1 \mid \mat{A}_2 \end{array} \mright]}{\mat{A}} \overbrace{ \mleft[ \begin{array}{c|c} \mat{S}1 & \mat{S}_2 \ \hline \mat{S}_3 & \mat{S}_4 \end{array} \mright]}{\mat{S}} \end{align}

\end{document}

enter image description here

Willie Wong
  • 24,733
  • 8
  • 74
  • 106
pixel
  • 1,357

1 Answers1

3

Some fine tuning may be required, and you should absolutely read the documentation for nicematrix. But here is an example of the second matrix that you posted.

enter image description here

\documentclass{article}
\usepackage{amsmath,nicematrix}
\begin{document}
\[ 
        \begin{bNiceArray}[last-col,margin]{w{c}{7em}|w{c}{3.5em}}
                \\
                (\mathbf{G}+\mathbf{R})\mathbf{U} & \mathbf{R}\mathbf{P}-\mathbf{C}  & \hspace*{8pt} m_1 \\
                \\
                \hline
                \Block{5-1}{\mathbf{U}} \\
                \\
                                                  & \mathbf{P} & \hspace*{8pt} m_2\\
                                                  \\
                &
                \CodeAfter
                \UnderBrace[yshift=5pt]{1-1}{8-1}{m_2}
                \UnderBrace[yshift=5pt]{1-2}{8-2}{m_1}
                \SubMatrix.{1-1}{3-2}\}[right-xshift=8pt]
                \SubMatrix.{4-1}{8-2}\}[right-xshift=8pt]
        \end{bNiceArray}
\]
\end{document}

Quick explanations:

  • bNiceArray specifies that you want to put it in brackets. using the ...Array version as opposed to the ...Matrix version gives you more control on the column specifications (which we use).
  • last-col allows you to add one final column outside the brackets. (Where we put the m_1 and m_2.)
  • margin puts a bit of margin, otherwise the \hline runs up against the brackets.
  • The column specifier w{c}{7em} puts in a fixed width column with width 7em and contents centered.
    • You can alternatively use some empty columns to get the horizontal spacing; I choose this to require less typing/counting.
  • Note that the last column is not included in the column specification.
  • Blank rows are included for vertical spacing.
  • Extra spaces are inserted ahead of m_1 and m_2 to accommodate the braces (to be put in later in the \SubMatrix block).
  • \CodeAfter allows you to mark up the matrix additionally.
    • Use \SubMatrix to put extra delimters, such as vertical braces (read the documentation for syntax); the extra xshift is to push the braces beyond the brackets; this is why we have to add space in front of the m_1 and m_2.
    • Use \UnderBrace to put horizontal braces across columns. Read the documentation for syntax. I put in an extra yshift to make it more closely resemble the spacing you have in your question.
Willie Wong
  • 24,733
  • 8
  • 74
  • 106
  • Thanks for it. One question though. I checked the documentation but I do not see how to add braces on the left size instead. So Imagine $m_1$ and $m_2$ braces being at the left (at the beginning) instead of right (at the end) as it is now. How does one do that? – pixel Jul 07 '23 at 19:45
  • Use \SubMatrix. The first argument is the delimiter on the left of the submatrix. In the above example I specified . for the "null delimiter". – Willie Wong Jul 07 '23 at 19:57