[Tex/LaTex] Setting over- and underbraces outside an matrix formula

bracesmath-modematrices

I want to typeset a matrix which consists of several submatrices. As they consist of some longer formulae I'd like to assign each a name. I tried to use \underbace and \overbrace. However now the braces and the letter appears inside the matrix and I'd like to have it above or below the matrix. What would you suggest here?

\documentclass{article}
\usepackage{amsmath}
\usepackage{xfrac}
\begin{document}
\begin{gather*}
H_{8kl}=
\begin{pmatrix}
    \overbrace{\sfrac{1}{2} (A+B)\otimes E + \sfrac{1}{2} (A-B)\otimes G}^{K} &
    \overbrace{\sfrac{1}{2} (A+B)\otimes F + \sfrac{1}{2} (A-B)\otimes H}^{L}\\
    \underbrace{\sfrac{1}{2} (C+D)\otimes E + \sfrac{1}{2} (C-D)\otimes G}_{M} &
    \underbrace{\sfrac{1}{2} (C+D)\otimes F + \sfrac{1}{2} (C-D)\otimes H}_{M}
  \end{pmatrix}
\end{gather*}
\end{document}

Best Answer

I \smashed the over and undersets, so that the matrix would not know of them. However, I had to compensate with a leading rule to accound for the vertical space that was smashed (the three 4ex expressions in the \rule can be changed in size to increase or decrease the gap above/below the expression).

Struts had to be added outside the over- and under-sets so as to get the parens to set to the right vertical size and also inside the over- and under-sets to get the braces to stand off from the expression appropriately.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xfrac}
\usepackage{lipsum}
\begin{document}
\lipsum[3]
\begin{gather*}
\rule[\dimexpr-4ex-\ht\strutbox]{0pt}{\dimexpr4ex+4ex+\baselineskip}
 H_{8kl}=
\begin{pmatrix}
    \strut\smash{\overbrace{\strut\sfrac{1}{2} (A+B)\otimes E + \sfrac{1}{2} (A-B)\otimes G}^{K}} &
    \strut\smash{\overbrace{\strut\sfrac{1}{2} (A+B)\otimes F + \sfrac{1}{2} (A-B)\otimes H}^{L}}\\
    \strut\smash{\underbrace{\strut\sfrac{1}{2} (C+D)\otimes E + \sfrac{1}{2} (C-D)\otimes G}_{M}} &
    \strut\smash{\underbrace{\strut\sfrac{1}{2} (C+D)\otimes F + \sfrac{1}{2} (C-D)\otimes H}_{M}}
  \end{pmatrix}
\end{gather*}
\lipsum[4]
\end{document}

enter image description here