2

I'm trying to draw a nested structure like below. The idea is to make the nodes in the lower box fit perfectly into the drawn outline. How could this be done?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{fit}
\usetikzlibrary{positioning}
\begin{document} 
\begin{tikzpicture} 
\node (0) {Hello}; 
\node (1) [right=3cm of 0]  { World}; 
\draw (1) -- (0) node [below] {} ;
\node [fit= (1) (0), draw] (4) {}; 
\node  (2) [below= of 0, ] {it's}; 
\node (3) [right=3cm of 2]  {really really here}; 
\draw (2) -- (3) node [below]  {}; 
\node [fit= (2) (3),  below=of 4, draw] (5) {}; 
\draw (4) -- (5) node [right] {} ; 
\node [fit= (4) (5), draw] (6) {}; 
\end{tikzpicture} 
\end{document}

enter image description here

All I can manage to do is this, but here, the structure isn't aligned correctly, because I have to give the position of node 2 before nodes 2 and 3 are fitted together.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{fit}
\usetikzlibrary{positioning}
\begin{document} 
\begin{tikzpicture} 
\node (0) {Hello}; 
\node (1) [right=3cm of 0]  { World}; 
\draw (1) -- (0) node [below] {} ;
\node [fit= (1) (0), draw] (4) {}; 
\node  (2) [below= of 0, ] {it's}; 
\node (3) [right=3cm of 2]  {really really here}; 
\draw (2) -- (3) node [below]  {}; 
\node [fit= (2) (3),   draw] (5) {}; 
\draw (4) -- (5) node [right] {} ; 
\node [fit= (4) (5), draw] (6) {}; 
\end{tikzpicture} 
\end{document}

1

2
  • 2
    Hi, welcome. Would you mind editing your examples so that they are compilable? (Add the necessary package and libraries, and also the definition of Rel if it's necessary.) Commented Mar 6, 2017 at 22:55
  • Sorry, corrected that above.
    – CharlesT
    Commented Mar 6, 2017 at 23:23

2 Answers 2

2

I assume, that you like something like this:

enter image description here

\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{fit, positioning}

\begin{document}
    \begin{tikzpicture}[node distance = 12mm and 0mm]
\node (0) {Hello};
\node (1) [right=3cm of 0]  {World};
\draw (0) -- (1);
\node (a) [draw, fit=(0) (1)] {};

\node (2) [below right=of 0.west] {it's};
\node (3) [right=3cm of 2]  {really, really here};
\draw (2) -- (3);
\node (b) [draw,fit=(2) (3)] {};

\draw (a) -- (a |- b.north);
\node (c) [draw,fit=(a) (b)] {};
\end{tikzpicture}
\end{document}

Let me note:

  • no one your MWE work, missing are essential package and libraries
  • used are function not defined in MWE (I remove them)
  • from question is not clear, if nodes had to positioned as is shown in above images, or you like to have centered horizontally

Addendum: horizontal centered, well what should be centered? Nodes around texts connected with line? First approximation to this is:

enter image description here

\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{fit, positioning}

\begin{document}
    \begin{tikzpicture}[node distance = 12mm and 15mm]
\node (n1)  {it's};
\node (n2) [right=3cm of n1]  {really, really here};
\draw (n1) -- (n2);
\node (n3) [draw,fit=(n1) (n2)] {};

\node (n4) [above  left=of n3.north]  {Hello};
\node (n5) [above right=of n3.north]  {World};
\draw (n4) -- (n5);
\node (n6) [draw, fit=(n4) (n5)] {};

\draw (n3) -- (n3 |- n6.south);
\node (n7) [draw,fit=(n3) (n6)] {};
\end{tikzpicture}
\end{document}
2
  • Thanks a lot, looks a lot better than mine, but yes, I was hoping to had them centered horizontally.
    – CharlesT
    Commented Mar 6, 2017 at 23:25
  • @cfr, sometimes I have lucky day (actually night), that it work :-)
    – Zarko
    Commented Mar 7, 2017 at 1:38
1

I think that a simple \rule will simplify the problem because it converts two nodes + fitting node in just one normal node.

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

\begin{document}
\begin{tikzpicture}
\node[draw] (a) {Hello \rule[.5ex]{3cm}{.4pt} World};
\node[draw, below=of a] (b) {it's \rule[.5ex]{3cm}{.4pt} really, really here};
\draw (a)--(b);
\node[draw, fit=(a) (b)]{};
\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 .