4

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.

4
  • 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 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
4

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.

2
  • 1
    Wow, thank you so much 😊 this is exactly what I was looking for – Sephya Jul 25 '20 at 21:46
  • @Sephya You're welcome! It was fun to do it. – egreg Jul 25 '20 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.