Math & Science ⇒ Diagonal overbraces in a matrix
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
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
NEW: TikZ book now 40% off at Amazon.com for a short time.

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Diagonal overbraces in a matrix
I'm not aware of a solution with the known commands. But you can use pgf/tikZ and some of its libraries.
The pstricks package offers similar capabilities.
Best regards and welcome to the board
Thorsten
Code: Select all
\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}
Best regards and welcome to the board
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Diagonal overbraces in a matrix
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
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
Diagonal overbraces in a matrix
Hi,
you can fine-tune the coordinates; a little example based on localghost's code:
you can fine-tune the coordinates; a little example based on localghost's code:
Code: Select all
\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,...
Re: Diagonal overbraces in a matrix
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
Thank you guys for all your help. I was at a loss until I came here

benbean
Re: Diagonal overbraces in a matrix
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?
Any help is greatly received,
benbean
Any help is greatly received,
benbean
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Diagonal overbraces in a 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.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? [...]
Code: Select all
\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}
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Diagonal overbraces in a matrix
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
b
