4

I would like to know how to connect nodes with curly braces in TikZ. The picture below shows what I want to do:

enter image description here

And this is what I already got:

\documentclass[class=minimal,border=0pt]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows.meta}

\begin{document}
\begin{tikzpicture}

\tikzstyle{myrect} = [rectangle,draw,thin,minimum width=3cm,minimum height=1cm,align=center]

\node (MD) [myrect] {Texttexttext};
\node (Z1) [myrect,above of=MD,yshift=0.5cm,minimum width=1.2cm] {Z1};
\node (Z2) [myrect,left of=Z1,xshift=-1.5cm,minimum width=1.2cm,opacity=.2,text opacity=.2] {Z2};
\node (Z3) [rectangle,left of=Z1,xshift=-0.5cm,minimum width=1.2cm] {$\cdots$};
\node (X1) [myrect,above of=Z1,xshift=1.5cm,yshift=0.5cm,minimum width=1cm] {X1};
\node (X2) [myrect,left of=X1,minimum width=1cm] {X2};
\node (X3) [myrect,left of=X2,minimum width=1cm] {X3};
\node (X4) [myrect,left of=X3,minimum width=1cm] {X4};
\node (X5) [myrect,left of=X4,minimum width=1cm] {X5};
\draw [decorate,decoration={brace,amplitude=0.5cm,mirror}] (Z1.south west) -- (Z1.south east);
\draw [decorate,decoration={brace,amplitude=0.5cm,mirror}] (X5.south west) -- (X1.south east);

\end{tikzpicture}
\end{document}

The braces still look a bit shitty, so is there an automatic and nice way to connect the nodes by the braces? Or do I have to position them exactly by coordinates?

Greets!

1 Answers1

4

It's not possible to "connect nodes by braces", but you can play a little bit with raise and amplitude options to get nicer results.

Following code shows some changes with your one:

The complete code is now:

\documentclass[class=minimal,border=2mm]{standalone}
%\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows.meta, positioning, decorations.pathreplacing}

\begin{document}
\begin{tikzpicture}[myrect/.style={rectangle, draw, thin, minimum height=1cm, align=center}]

\node (MD) [myrect, minimum width=3cm] {Texttexttext};
\node (Z1) [myrect, above=4mm of MD, minimum width=1.2cm] {Z1};
\node (Z2) [myrect, left = of Z1, minimum width=1.2cm, opacity=.2, text opacity=.2] {Z2};

\path (Z2) -- (Z1) node[midway]{\dots};

\node (X3) [myrect,above= 4mm of Z1] {X3};
\node (X4) [myrect,left = -\pgflinewidth of X3] {X4};
\node (X5) [myrect,left = -\pgflinewidth of X4] {X5};
\node (X2) [myrect,right = -\pgflinewidth  of X3] {X2};
\node (X1) [myrect,right = -\pgflinewidth of X2] {X1};

\draw [decorate,decoration={brace,amplitude=3mm,mirror, raise=.5mm}] (Z1.south west) -- (Z1.south east);
\draw [decorate,decoration={brace,amplitude=3mm,mirror,raise=.5mm}] (X5.south west) -- (X1.south east);

\end{tikzpicture}
\end{document}

and the result

enter image description here

Ignasi
  • 136,588