Math & Science ⇒ Diagonal overbraces in a matrix
Diagonal overbraces in a matrix
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
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Diagonal overbraces in a matrix
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
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Diagonal overbraces in a matrix
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
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}
Re: Diagonal overbraces in a matrix
Thank you guys for all your help. I was at a loss until I came here

benbean
Re: Diagonal overbraces in a matrix
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}
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Diagonal overbraces in a matrix
b
