# Brace diagram in TikZ

I apologize if this has already been covered in some other posts, but I couldn't find it anywhere and I'm not even sure if "brace diagram" is the correct name in English.

I have found some examples of probability trees, and some others that are close (like this: Draw Curly Braces in TikZ), but while playing with them I couldn't get the correct output (The part of the first "text here" when out of boundaries into the brace).

What I'm trying to do is something like this with TikZ: I know there are some ways to do this with mathmode, but I'm really interested in learning a little more about TikZ and how it works for diagrams like this.

• It might be helpful if you were to post your TikZ code (in a working example) so that people can check it out and perhaps understand why it's not doing what you want. May 3, 2013 at 15:13
• @CharlesStaats I don't have a tikzpicture code, that's why I have a graphic representation of what I'm trying to achieve. I want to know how this could be done with tikz. May 3, 2013 at 15:16
• If I'm correctly reading your question, you do have tikz code--it just doesn't give the right output: "The first part of 'text here' went out of the boundaries into the brace." May 3, 2013 at 15:31
• @CharlesStaats it is the code in the linked question mentioned. I was just playing around with it changing the p1 for "text here" and as I mentioned, it went out of bounds May 3, 2013 at 15:58
• First, that particular problem will probably be solved by adding the key left to the relevant node, as in node [left,black,midway,xshift=-0.6cm] {\footnotesize $P_1$}; you will probably also need to adjust the xshift value after doing this. Second, braces in TikZ are generally used to add labels after the "main objects" have already been placed. Using them as part of the "structure" of a tree is certainly possible, but it hardly seems worth the effort when the cases environment is available. May 3, 2013 at 16:16

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,decorations.pathreplacing}

\begin{document}

\begin{tikzpicture}
\node (main) {Text here};
\begin{scope}[node distance=1em]
\node [right=of main] (t2) {Some text2};
\node [above=of t2]   (t1) {Some text1};
\node [below=of t2]   (t3) {Some text3};
\end{scope}
\draw[decorate,decoration={brace,mirror}] (t1.north west) -- (t3.south west);

\begin{scope}[node distance=.5em]
\node [right =of t1,yshift= .5em] (st2) {Some text 1.2};
\node [right =of t1,yshift=-.5em] (st3) {Some text 1.3};
\node [right =of t1,yshift=  1.5em] (st1) {Some text 1.1};
\node [right =of t1,yshift= -1.5em] (st4) {Some text 1.4};
\end{scope}
\draw[decorate,decoration={brace,mirror}] (st1.north west) -- (st4.south west);
\end{tikzpicture}

\end{document} The schemata package is designed just for these brace diagrams:

\documentclass{article}
\usepackage{schemata}
\newcommand\AB{\schema{\schemabox{#1}}{\schemabox{#2}}}

\begin{document}

\AB{text here}
{
\AB{Some text 1}
{
text 1.1 \\
text 1.2 \\
text 1.3 \\
text 1.4
}\\
Some text 2 \\
Some text 3
}

\end{document} • This is actually a great answer! Jun 19, 2013 at 0:29

Why tikz? Why not simply cases in an equation?

\documentclass{amsart}

\begin{document}

\begin{displaymath}
\text{some text} \begin{cases}
\text{some text}_1 &
\begin{cases}
\text{text 1.1}\\
\text{text 1.2}\\
\text{text 1.3}\\
\text{text 1.4}
\end{cases}
\\
\text{some text}_2\\
\text{some text}_3
\end{cases}
\end{displaymath}

\end{document} • Well, because as I stated in my question, I'm trying to learn how to do this with Tikz May 3, 2013 at 14:48
• @MarioS.E. May be there is no pressing need for TikZ in this example without a sample TikZ code unless you need something fancy May 3, 2013 at 14:56
• The result is wrong with this code. You don't get the example given in the question. May 3, 2013 at 16:34
• @AlainMatthes: Did you mean the spacing between text2 and text3 is not consistent with the spacing between text1 and text2? May 3, 2013 at 16:47
• @AlainMatthes One could simply \smash the inner cases environment. May 3, 2013 at 17:10

An answer using the matrix library (updated according to @Qrrbrbirlbel's comment in @Alex's answer): \documentclass{amsart}

\usepackage{tikz}
\usetikzlibrary{matrix,calc}
\begin{document}

\centering
text here
\begin{tikzpicture}
\tikzset{
every left delimiter/.style={xshift=1.5ex}, % shorten space b/w brace and text
column 1/.style={anchor=base west}, % left-align column 1
row sep=6ex, % consistent row spacing
baseline={($(M.center)+(0,-.5ex)$)} % mid-align 'some text' and matrix
}

\matrix(M)[matrix of math nodes,left delimiter=\{]
{
\text{some text}_1
\smash{
\begin{cases}
\text{text 1.1}\\
\text{text 1.2}\\
\text{text 1.3}\\
\text{text 1.4}
\end{cases}
}\\
\text{some text}_2\\
\text{some text}_3\\
};
\end{tikzpicture}

\end{document}

• Well, \matrix cannot be nested...
– Alex
May 3, 2013 at 18:28
• @Alex: Yes, unfortunately... May 3, 2013 at 18:46