5

I am trying to achieve having overbraces and right braces to a matrix to explain columns and rows. This is what I achieved so far :

Matrix

This is the code I have used :

\documentclass{article}
\usepackage{amsmath}

\newcommand\overmat[2]{% \makebox[0pt][l]{$\smash{\color{white}\overbrace{\phantom{% \begin{matrix}#2\end{matrix}}}^{\text{\color{black}#1}}}$}#2} \newcommand\bovermat[2]{% \makebox[0pt][l]{$\smash{\overbrace{\phantom{% \begin{matrix}#2\end{matrix}}}^{\text{#1}}}$}#2} \newcommand\partialphantom{\vphantom{\frac{\partial e_{P,M}}{\partial w_{1,1}}}}

\begin{document}

$ \begin{matrix} \begin{pmatrix} \bovermat{$m_1$ colonnes}{\lambda_1 & 0 & \ldots & 0 & 0} & \bovermat{$n - m_1$ colonnes}{ & & & & } \[0.5em] % 0 & \lambda_1 & \ldots & 0 & 0 & & & & & \[0.5em] % 0 & 0 & \ddots & 0 & 0 & & & \mbox{\Huge U} & & \[0.5em] % 0 & 0 & \ldots & \lambda_1 & 0 & & & & & \[0.5em] % 0 & 0 & \ldots & 0 & \lambda_1 & & & & & \[0.5em] % & & & & & & & & & \[0.5em] % & & & & & & & & & \[0.5em] % & & \mbox{\Huge O} & & & & & \mbox{\Huge V} & & \[0.5em] % & & & & & & & & & \[0.5em] % & & & & & & & & & \[0.5em] \end{pmatrix} \begin{aligned} &\left.\begin{matrix} \partialphantom \[0.5em] \partialphantom \[0.5em] \partialphantom \[0.5em] \partialphantom \[0.5em] \partialphantom \[0.5em] \end{matrix} \right} % m_1 \text{ lignes}\ &\left.\begin{matrix} \partialphantom \[0.5em] \partialphantom \[0.5em] \partialphantom \[0.5em] \partialphantom \[0.5em] \partialphantom \[0.5em] \end{matrix}\right}% n - m_1 \text{ lignes}\ \end{aligned} \end{matrix}$

\end{document}

Now the only problem I have, is that I would want the first overprice to encompass up to the last zero on the first line of the matrix and the second brace should start at the end of the first and go up to the end of the matrix.

I am however at a total loss on how I should be doing it.

Any help would be appreciated.

Sephya
  • 473
  • 3
  • 13
  • 2
    What is this \partialphantom command? – Bernard Jul 25 '20 at 19:40
  • To be honest, I don't know, I adapted my code from https://tex.stackexchange.com/a/108053/154126 to get somewhat what I wanted – Sephya Jul 25 '20 at 19:45
  • 1
    @Sephya There, the definition of this macro is given as follows \newcommand\partialphantom{\vphantom{\frac{\frac{\partial e_{P,M}}}{\partial w_{1,1}}} update your code with the definition of this macro. – AndréC Jul 25 '20 at 20:07
  • Ohhh thanks, I did, but it doesn't solve the fact that my 2 overbraces are still not aligned correctly – Sephya Jul 25 '20 at 20:12

2 Answers2

3

Complicated, but doable.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

[ % some local definitions \newcommand\explainA{% \overbrace{% \hphantom{\begin{matrix}\lambda_1&\lambda_1&\dots&\lambda_1&\lambda_1\end{matrix}}% }^{\text{$m_1$ colonnes}}% } \newcommand{\explainB}{% \overbrace{% \hphantom{\begin{matrix}0&0&0&0&0\end{matrix}}% }^{\text{$n-m_1$ colonnes}}% } \newcommand{\explainC}{% \left.\vphantom{\begin{matrix}0\0\\ddots\0\0\end{matrix}}\right}% \text{\scriptsize$m_1$ lignes}% } \newcommand{\explainD}{% \left.\vphantom{\begin{matrix}0\0\0\0\0\0\end{matrix}}\right}% \text{\scriptsize$n-m_1$ lignes}% } \settowidth{\dimen0}{% $\begin{pmatrix}\vphantom{\begin{matrix}0\0\0\0\0\0\0\end{matrix}}\end{pmatrix}$% } \settowidth{\dimen2}{$\explainB$} \begin{matrix} \begin{matrix}\hspace{0.5\dimen0}\explainA&\explainB\hspace{0.5\dimen0}\end{matrix} \[-0.5ex] \begin{pmatrix} \begin{matrix} \lambda_1 & 0 & \dots & 0 & 0 \ 0 & \lambda_1 & \dots & 0 & 0 \ 0 & 0 & \ddots & 0 & 0 \ 0 & 0 & \dots & \lambda_1 & 0 \ 0 & 0 & \dots & 0 & \lambda_1 \end{matrix} & \makebox[\dimen2]{\Huge$U$} \ \vphantom{\begin{matrix}0\0\0\0\0\0\end{matrix}}\text{\Huge$O$} & \text{\Huge$V$} \end{pmatrix} &\hspace*{-1em}\begin{matrix} \explainC\hfill \ \explainD \end{matrix} \end{matrix} ]

\end{document}

You might enjoy studying it. There are two “guesses”: the amount by which the top line should be lowered and the amount by which the explanations on the right have to be pushed left.

enter image description here

I think it would be simpler to just write the block matrix and give the explanation of the sizes in the text.

egreg
  • 1,121,712
1

Here is a solution with {NiceMatrix} of nicematrix (≥ 6.4 of 2021-11-23).

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\setcounter{MaxMatrixCols}{11}

[\begin{NiceMatrix}[columns-width=4mm] \lambda_1 & 0 & \cdots & 0 & 0 & \NotEmpty \Block{5-5}<\Huge>{U}& & & & \NotEmpty & \Block{5-1}{\quad m_1 \text{ lignes}}\ 0 & \lambda_1 & \cdots & 0 & 0 & \ 0 & 0 & \smash{\ddots} & 0 & 0 & \ 0 & 0 & \cdots & \lambda_1 & 0 & \ 0 & 0 & \cdots & 0 & \lambda_1 & \ \Block{5-5}<\Huge>{O} & & & & & \Block{5-5}<\Huge>{V} & & & & & \Block{5-1}{\quad n-m_1 \text{ lignes}} \ \ \ \ \ \CodeAfter \SubMatrix({1-1}{10-10}) \OverBrace[shorten,yshift=2mm]{1-1}{1-5}{m_1 \text{ colonnes}} \OverBrace[shorten,yshift=2mm]{1-6}{1-10}{n-m_1 \text{ colonnes}} \SubMatrix{.}{1-1}{5-10}{}}[xshift=4mm] \SubMatrix{.}{6-1}{10-10}{}}[xshift=4mm] \end{NiceMatrix}]

\end{document}

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

Output of the above code

F. Pantigny
  • 40,250