## LaTeX forum ⇒ Math & Science ⇒ Diagonal overbraces in a matrix

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
benbean
Posts: 6
Joined: Thu Mar 11, 2010 9:40 pm

### Diagonal overbraces in a matrix

I have looked on the web for an answer to this but have had no luck yet so hopefully someone can offer some help here.
I have the matrix below:

\begin{pmatrix}
x_{1,1} & x_{1,2} & \cdots & x_{1,j} \\
x_{2,1} & x_{2,2} & \cdots & x_{2,j} \\
\vdots & \vdots & \ddots & \vdots \\
x_{i,1} & x_{i,2} & \cdots & x_{i,j}
\end{pmatrix}

Is it possible to group the elements x_{1,1}, x_{2,2}, \ddots, x_{i,j} in a diagonal curly brace? Possibly in a form like \overbrace or \underbrace?

If this is possible could I then have this brace with text?

Thanks,
benbean

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
I'm not aware of a solution with the known commands. But you can use pgf/tikZ and some of its libraries.
\documentclass{article}\usepackage{tikz}\usetikzlibrary{matrix,decorations.pathreplacing} \begin{document}   \begin{tikzpicture}[decoration={brace,amplitude=5pt}]     \matrix (magic) [matrix of math nodes,left delimiter=(,right delimiter=)] {       x_{1,1} & x_{1,2} & \cdots & x_{1,j} \\       x_{2,1} & x_{2,2} & \cdots & x_{2,j} \\       \vdots & \vdots & \ddots & \vdots \\       x_{i,1} & x_{i,2} & \cdots & x_{i,j} \\     };     \draw[decorate,red] (magic-1-1.north) -- (magic-4-4.north) node[above=5pt,midway,sloped] {label};   \end{tikzpicture}\end{document}

The pstricks package offers similar capabilities.

Best regards and welcome to the board
Thorsten
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

benbean
Posts: 6
Joined: Thu Mar 11, 2010 9:40 pm
Thanks a lot Thorsten exactly what I had in mind!

Just a small query - Is it possible to extend the curly brace so as to enclose the two end elements, namely the x_{1,1} and x_{i,j} elements? The solution you posted seems to have the brace stop over the 'midpoint' of each element.

I am very new to LaTeX so the learning curve is looking steep at the minute .

Thanks again
b

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm
Hi,

you can fine-tune the coordinates; a little example based on localghost's code:

\documentclass{article}\usepackage{tikz}\usetikzlibrary{matrix,decorations.pathreplacing,calc} \begin{document}   \begin{tikzpicture}[decoration={brace,amplitude=5pt}]     \matrix (magic) [matrix of math nodes,left delimiter=(,right delimiter=)] {       x_{1,1} & x_{1,2} & \cdots & x_{1,j} \\       x_{2,1} & x_{2,2} & \cdots & x_{2,j} \\       \vdots & \vdots & \ddots & \vdots \\       x_{i,1} & x_{i,2} & \cdots & x_{i,j} \\     };     \draw[decorate,red] ($(magic-1-1.north west)+(0.2,0.15)$) -- (magic-4-4.north east) node[above=5pt,midway,sloped] {label};   \end{tikzpicture}\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...

benbean
Posts: 6
Joined: Thu Mar 11, 2010 9:40 pm
Thanks gmedina, I am able to get what I am after with your suggestion.

Thank you guys for all your help. I was at a loss until I came here
benbean

benbean
Posts: 6
Joined: Thu Mar 11, 2010 9:40 pm
This is a bit off topic but how would I write this matrix in an equation style? If it is defined as A = <matrix>, how do I get it so that the "A = " part is centered inline with the matrix?

benbean

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
benbean wrote:This is a bit off topic but how would I write this matrix in an equation style? If it is defined as A = <matrix>, how do I get it so that the "A = " part is centered inline with the matrix? [...]

I hope that you only mean the alignment with respect to the equal sign and not how you can get it into a math environment in general. Since the origin of the tikzpicture environment is put at the lower left corner by default, it needs an additional option.
\documentclass{article}\usepackage{amsmath}\usepackage{tikz}\usetikzlibrary{matrix,decorations.pathreplacing,calc} \begin{document}$\boldsymbol{A}= \begin{tikzpicture}[decoration={brace,amplitude=5pt},baseline=(current bounding box.west)] \matrix (magic) [matrix of math nodes,left delimiter=(,right delimiter=)] { x_{1,1} & x_{1,2} & \cdots & x_{1,j} \\ x_{2,1} & x_{2,2} & \cdots & x_{2,j} \\ \vdots & \vdots & \ddots & \vdots \\ x_{i,1} & x_{i,2} & \cdots & x_{i,j} \\ }; \draw[decorate,red] ((magic-1-1.north west)+(0.2,0.15)) -- (magic-4-4.north east) node[above=5pt,midway,sloped] {label}; \end{tikzpicture}$\end{document}
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

benbean
Posts: 6
Joined: Thu Mar 11, 2010 9:40 pm
Yes it was only the alignment I was trying to fix. Your code worked again so many thanks again! It's all looking how I intended, thanks for all your help.

b

### Who is online

Users browsing this forum: No registered users and 0 guests