I need to add overbrace on columns of a matrix. I tried How do I label different rows or columns of a matrix using braces? and Build a matrix with overbrace on some columns , They both work until no subscript or entry with different length is added to entries, after adding subscript it is not working properly. The following images shows the problem
This is the code
\[ \vphantom{% phantom stuff for correct box dimensions
\begin{matrix}
\overbrace{XYZ}^{\mbox{$R$}}\\ \\ \\ \\ \\ \\
\underbrace{pqr}_{\mbox{$S$}}
\end{matrix}}%
\begin{matrix}% matrix for left braces
\vphantom{a}\\
\coolleftbrace{A}{e \\ y\\ y}\\
\coolleftbrace{B}{y \\i \\ m}
\end{matrix}%
\begin{bmatrix}
a & \coolover{R}{b & c & d & \cdots & y & h}\\
e & a & g & h & x & x & x \\
y & y & a & y & y & y & y \\
y & y & y & y & y & y & y \\
y & y & y & y & y & y & y \\
i & j & k & l & x & x & x \\
m & \coolunder{S}{n & o} & \coolunder{W}{p & x & x} & x
\end{bmatrix}%
\begin{matrix}% matrix for right braces
\coolrightbrace{x \\ x \\ y\\ y}{T}\\
\coolrightbrace{y \\ y \\ x }{U}
\end{matrix}\]
and after subscript the overbrace R is not on h anymore
This is the code
\[ \vphantom{% phantom stuff for correct box dimensions
\begin{matrix}
\overbrace{XYZ}^{\mbox{$R$}}\\ \\ \\ \\ \\ \\
\underbrace{pqr}_{\mbox{$S$}}
\end{matrix}}%
\begin{matrix}% matrix for left braces
\vphantom{a}\\
\coolleftbrace{A}{e \\ y\\ y}\\
\coolleftbrace{B}{y \\i \\ m}
\end{matrix}%
\begin{bmatrix}
a_1 & \coolover{R}{b_{1,2} & b_{2,s_1+1} & 0 & \cdots & 0 & h}\\
b_{1,2} & a_2 & b_{2,s_2+1} & h & x & x & x \\
b_{2,s_2+4} & b_{2,s_2+1} & a_3 & y & y & y & y \\
y & y & y & a_{s_{r+1}} & y & y & y \\
y & y & y & y & y & y & y \\
i & j & k & l & x & x & x \\
m & \coolunder{S}{n & o} & \coolunder{W}{p & x & x} & x
\end{bmatrix}%
\begin{matrix}% matrix for right braces
\coolrightbrace{x \\ x \\ y\\ y}{T}\\
\coolrightbrace{y \\ y \\ x }{U}
\end{matrix}\]



\documentclass{...}and ending with\end{document}. – Zarko Aug 18 '18 at 16:05