3

I want to have 4 rectangles (with color X) and an bigger rectangle covering these 4 (with color Y). But, when I "fit" the bigger rectangle, I am losing the other 4.

\begin{tikzpicture}[
    s1/.style       ={rectangle, rounded corners, draw=blue!60, fill=red!5, very thick, minimum size=40},
    s2/.style       ={rectangle, rounded corners, draw=green!60, fill=blue!5, very thick, minimum size=40},
    s3/.style       ={rectangle, rounded corners, draw=red, fill=yellow,  very thick, minimum size=40},
    ]
    
    %Nodes

    \node[s1]       (n1)                            {$bondid_i$};
    \node[s1]       (n2)    [right=of n1]           {$G_1$};
    \node[s1]       (n3)    [right=of n2]           {$G_2$};
    \node[s1]       (n4)    [right=of n3]           {$pk_i$};
    \node[s3]       (n5)    [fit=(n1) (n2) (n3) (n4)]   {a};

\end{tikzpicture}

How to "bring to front" the other 4 rectangles ?

enter image description here

1
  • You can use TikZ layers. See, for example, this answer.
    – jlab
    Commented May 21 at 9:17

1 Answer 1

4

Simply write the nodes in a single path and say that the last node is behind the path (I've added this to the s3 style)..

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit}

\begin{document}
\begin{tikzpicture}[
    s1/.style       ={rectangle, rounded corners, draw=blue!60, fill=red!5, very thick, minimum size=40},
    s2/.style       ={rectangle, rounded corners, draw=green!60, fill=blue!5, very thick, minimum size=40},
    s3/.style       ={rectangle, rounded corners, draw=red, fill=yellow,  very thick, minimum size=40,behind path}]
    
    %Nodes
   \node[s1](n1) {$bondid_i$}
    node[s1](n2) [right=of n1] {$G_1$}
    node[s1](n3) [right=of n2] {$G_2$}
    node[s1](n4) [right=of n3] {$pk_i$}
    node[s3](n5) [fit=(n1) (n2) (n3) (n4)] {a};
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .