LaTeX forum ⇒ Math & ScienceDiagonal 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

Postby benbean » Thu Mar 11, 2010 9:51 pm

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

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Thu Mar 11, 2010 10:16 pm

I'm not aware of a solution with the known commands. But you can use pgf/tikZ and some of its libraries.
  1. \documentclass{article}
  2. \usepackage{tikz}
  3. \usetikzlibrary{matrix,decorations.pathreplacing}
  4.  
  5. \begin{document}
  6. \begin{tikzpicture}[decoration={brace,amplitude=5pt}]
  7. \matrix (magic) [matrix of math nodes,left delimiter=(,right delimiter=)] {
  8. x_{1,1} & x_{1,2} & \cdots & x_{1,j} \\
  9. x_{2,1} & x_{2,2} & \cdots & x_{2,j} \\
  10. \vdots & \vdots & \ddots & \vdots \\
  11. x_{i,1} & x_{i,2} & \cdots & x_{i,j} \\
  12. };
  13. \draw[decorate,red] (magic-1-1.north) -- (magic-4-4.north) node[above=5pt,midway,sloped] {label};
  14. \end{tikzpicture}
  15. \end{document}

The pstricks package offers similar capabilities.


Best regards and welcome to the board
Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ 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

Postby benbean » Fri Mar 12, 2010 12:27 am

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 :D .

Thanks again
b

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

Postby gmedina » Fri Mar 12, 2010 3:45 am

Hi,

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

  1. \documentclass{article}
  2. \usepackage{tikz}
  3. \usetikzlibrary{matrix,decorations.pathreplacing,calc}
  4.  
  5. \begin{document}
  6. \begin{tikzpicture}[decoration={brace,amplitude=5pt}]
  7. \matrix (magic) [matrix of math nodes,left delimiter=(,right delimiter=)] {
  8. x_{1,1} & x_{1,2} & \cdots & x_{1,j} \\
  9. x_{2,1} & x_{2,2} & \cdots & x_{2,j} \\
  10. \vdots & \vdots & \ddots & \vdots \\
  11. x_{i,1} & x_{i,2} & \cdots & x_{i,j} \\
  12. };
  13. \draw[decorate,red] ($(magic-1-1.north west)+(0.2,0.15)$) -- (magic-4-4.north east) node[above=5pt,midway,sloped] {label};
  14. \end{tikzpicture}
  15. \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

Postby benbean » Fri Mar 12, 2010 2:35 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

Postby benbean » Fri Mar 12, 2010 7:18 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?

Any help is greatly received,
benbean

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Fri Mar 12, 2010 8:31 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.
  1. \documentclass{article}
  2. \usepackage{amsmath}
  3. \usepackage{tikz}
  4. \usetikzlibrary{matrix,decorations.pathreplacing,calc}
  5.  
  6. \begin{document}
  7. \[
  8. \boldsymbol{A}=
  9. \begin{tikzpicture}[decoration={brace,amplitude=5pt},baseline=(current bounding box.west)]
  10. \matrix (magic) [matrix of math nodes,left delimiter=(,right delimiter=)] {
  11. x_{1,1} & x_{1,2} & \cdots & x_{1,j} \\
  12. x_{2,1} & x_{2,2} & \cdots & x_{2,j} \\
  13. \vdots & \vdots & \ddots & \vdots \\
  14. x_{i,1} & x_{i,2} & \cdots & x_{i,j} \\
  15. };
  16. \draw[decorate,red] ($(magic-1-1.north west)+(0.2,0.15)$) -- (magic-4-4.north east) node[above=5pt,midway,sloped] {label};
  17. \end{tikzpicture}
  18. \]
  19. \end{document}
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ 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

Postby benbean » Fri Mar 12, 2010 11:54 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 :)


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 0 guests