TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What I'm trying to achieve is a code structure to draw this kind of diagram:


I need to decorate a two-rows matrix grouping one or more columns with a square bracket above them, and then again with a square bracket grouping one or more subgroups (there may be more than three levels of nested groups).

At first I tried nesting matrices with above delimiter=\lbrack, but TikZ told me that You cannot nest pgfmatrix environments, yet, so I ended up with something like this

  group/.style={inner sep=0pt},
  brace/.style={very thick,decorate,decoration={brace,amplitude=10pt}},
  square/.style={-,to path={-- ++(0,.25) -| (\tikztotarget)}}
\matrix (A) [matrix of nodes]
  1--2 & 3--4 & 5 &
  6--7 & 8--9 & 10 &
  11--12 & 13--14 & 15--16 \\
  I & V--I--V & V--IV &
  V$^6$--IV & V$^7$ & V--IV &
  I--V--I--IV & V$^7$--I & V--VI \\
\node (gdg) [group,fit=(A-1-1)(A-2-1)] {};
\node (boh) [group,fit=(A-1-2)(A-2-2)] {};
\node (z) [group,fit=(A-1-3)(A-2-3)] {};
\node (frase-a) [group,fit=(gdg)(boh)(z)] {};
\draw[square] ([yshift=.5cm]gdg.west) to ([yshift=.5cm]gdg.east);
\draw[square] ([yshift=.5cm]boh.west) to ([yshift=.5cm]boh.east);
\draw[square] ([yshift=.5cm]z.west) to ([yshift=.5cm]z.east);

\draw[square] ([yshift=1cm]frase-a.west) to ([yshift=1cm]frase-a.east);

\draw[brace] ([yshift=2cm]A.west) -- ([yshift=2cm]A.east);

where I first draw the matrix, then I group each column in an invisible node (with fit) and then draw the square brackets as paths from/to west/east anchor point of groups, shifting coordinates on the y-axis. Which is quite unmaintainable and ugly. Of course the main target is to build something that could adapt to the variable width of matrix columns. Any suggestion would be very appreciated!

share|improve this question
Welcome to TeX.sx! – Jubobs Apr 26 '13 at 22:59
Perhaps you can adapt the solutions from Matrix with labels nested in braces for this. – Peter Grill Apr 26 '13 at 23:36
Since it came out that the solution might not involve TikZ nor matrices nor decorations, should I change the title of my question? – Heruan Apr 27 '13 at 9:24

This doesn't use TiKz, and could be prettier but

enter image description here

 \vrule\@width .7pt\@height3pt\hbox{$\smash-\mkern-3mu$}%
  \vrule\@width .7pt}


\multicolumn{3}{c}{\mathrm{something}\quad b/a'}&
\multicolumn{3}{c}{\mathrm{something}\quad b'/a}\\
1-2&3-4&5  &6-7   &8-9&10&11-12&13-14     &15-16\\
I  &V  &V^6&V(I-N)&X  &Y &Z     &(V^3)(X-V)&V^5
share|improve this answer

Inspired by David Carlisle answer, I came up with this solution:

  }^{\text{frase }a}
  }^{\text{frase }b/a'}
  }^{\text{frase }a'/b}

which results in:


Now it's flexible and maintainable, I just need to find out to add labels outside the brace on the left of each line.

share|improve this answer
\llap{hello\hspace{1cm}}1-2 would out hello to the left of the 1-2 entry – David Carlisle Apr 27 '13 at 22:59
+1 for being inspired by me:-) – David Carlisle Apr 27 '13 at 23:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.