# How to add two underbraces and two sidebraces in the same equation system?

I would like to add two underbraces and two sidebraces in the same equation system as shown in the picture attached. I already managed to add the underbraces but the left and right braces are too long. Furthermore, I couldn't add the sidebraces.

My code is:

\documentclass{article} \usepackage{amsmath} \begin{document}
\begin{align}
\left\begin{array}{c c c c c c}
a_{11} & \cdots & a_{1m} & a_{1(m+1)} & \cdots & a_{1(2m)}  \\
\vdots & \ddots & \vdots & \vdots & \ddots & \vdots  \\
a_{n1} & \cdots & a_{nm} & a_{n(m+1)} & \cdots & a_{n(2m)} \\
\multicolumn{3}{c}{\underbrace{\rule{2cm}{0pt}}_{A_{n}}}
& \multicolumn{3}{c}{\underbrace{\rule{3.5cm}{0pt}}_{A_{k}}}
\end{array}\right \times
\left(\begin{array}{c}
s_{1} \\
\vdots\\
s_{m} \\
s_{m+1} \\
\vdots \\
s_{2m}
\end{array}\right)
= z \end{align} \end{document}


Does anyone know how to do that? Thank you!

• Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – dexteritas Sep 11 '17 at 14:43
• See this question, tex.stackexchange.com/questions/331506/…, for the side-brace question. – Steven B. Segletes Sep 11 '17 at 14:48

I replaced align with equation, since there were no align tabs and only one equation.

\documentclass{article}
\usepackage{amsmath}
\usepackage[usestackEOL]{stackengine}
\stackMath
\begin{document}
$$\left( \vphantom{\begin{array}{c}a\\a\\a\\\end{array}} \smash{\underbrace{\begin{array}{c c c } a_{11} & \cdots & a_{1m} \\ \vdots & \ddots & \vdots \\ a_{n1} & \cdots & a_{nm} \end{array}}_{A_n}}\,\, \smash{\underbrace{\begin{array}{c c c } a_{1(m+1)} & \cdots & a_{1(2m)} \\ \vdots & \ddots & \vdots \\ a_{n(m+1)} & \cdots & a_{n(2m)} \end{array}}_{A_k}} \right) \times \left(\begin{array}{c} s_{1} \\ \vdots\\ s_{m} \\ s_{m+1} \\ \vdots \\ s_{2m} \end{array}\right) \setstackgap{L}{1.2\normalbaselineskip} \vcenter{\hbox{\stackunder[1pt]{% \left.{\Centerstack{\\ \\}}\right\}\scriptstyle S_m% }{ \left.{\Centerstack{\\ \\}}\right\}\scriptstyle S_k% }}} = z$$
\end{document}


• Thank you so much for your help. This is honestly more than I expected! – Marvin Bachmann Sep 11 '17 at 15:56

You might do like this:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

$\underset{ \underbrace{ \hphantom{\begin{matrix}a_{1,m} & \cdots & a_{n,m}\end{matrix}} }_{\displaystyle A_n} \hspace{2\arraycolsep} \underbrace{ \hphantom{\begin{matrix}a_{n+1,m} & \cdots & a_{n+k,m}\end{matrix}} }_{\displaystyle A_k} }{ \begin{pmatrix} a_{1,1} & \cdots & a_{n,1} & a_{n+1,1} & \cdots & a_{n+k,1} \\ \vdots & \ddots & \vdots & \vdots & \ddots & \vdots \\ a_{1,m} & \cdots & a_{n,m} & a_{n+1,m} & \cdots & a_{n+k,m} \end{pmatrix} } \times \begin{pmatrix} s_{1} \\ \vdots\\ s_{m} \\ s_{m+1} \\ \vdots \\ s_{m+k} \end{pmatrix} \hspace{-0.5em} \begin{matrix} \left.\begin{matrix} \vphantom{s_1}\\\vphantom{\vdots}\\\vphantom{s_m} \end{matrix}\right\rbrace S_m \hfill \\ \left.\begin{matrix} \vphantom{s_{m+1}}\\\vphantom{\vdots}\\\vphantom{s_{m+k}} \end{matrix}\right\rbrace S_k \hfill \end{matrix} = z$

\end{document}


However, you should consider a different presentation:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

$\begin{pmatrix}\vphantom{\bigg|} A_n & A_k \end{pmatrix} \begin{pmatrix} \vphantom{\bigg|} S_n \\ \vphantom{\bigg|} S_k \end{pmatrix} =z$
where
\begin{align*}
A_n &=
\begin{pmatrix}
a_{1,1} & \cdots & a_{n,1} \\
\vdots  & \ddots & \vdots  \\
a_{1,m} & \cdots & a_{n,m}
\end{pmatrix}
& S_n &=
\begin{pmatrix}
s_{1} \\
\vdots\\
s_{m}
\end{pmatrix}
\\
A_k &=
\begin{pmatrix}
a_{n+1,1} & \cdots & a_{n+k,1} \\
\vdots & \ddots & \vdots  \\
a_{n+1,m} & \cdots & a_{n+k,m}
\end{pmatrix}
& S_k &=
\begin{pmatrix}
s_{m+1} \\
\vdots \\
s_{m+k}
\end{pmatrix}
\end{align*}

\end{document}


• oh my god thank you so much for your help! I really appreciate it! Is it possible to ada label like \label{eq:01-A} to your first solution? It seems like latex is just ignoring the label. Thanks again! – Marvin Bachmann Sep 11 '17 at 15:55
• @MarvinBachmann Use and , so it will be numbered and will accept a \label. – egreg Sep 11 '17 at 15:58