1

I'm new to LateX and I would like to draw a complex picture which includes a couple of nodes. I have simplified my problem. My main problem is with drawing overlapping nodes. I have the following code, but I don't know how to make the overlapping that I want. Any help would be appreciated.

     \documentclass[border=1pt, tikz]{standalone}

\usetikzlibrary{positioning, fit}

\begin{document}
\begin{tikzpicture}[draw=black, scale=1, transform shape
    , every node/.style = {rectangle, draw=black, align=center, inner xsep=6mm, inner ysep=3mm}
    ]
    % change default arrow style
    \tikzset{very thick, ->, -latex, shorten <=0pt, shorten >=0pt}
    \node[name=outer, minimum width = 4cm, minimum height= 3cm] {};
    \node[name=inner, above=(2mm of outer.south)] {Inner Text};
     \node[name=inner2, above=(10mm of outer.south)] {Inner Text2};

\end{tikzpicture}
\end{document}

What this code produces is like the following: Current Output

And what I expect is as the following picture shows: enter image description here

Update: To describe my goal better, I would say that I need to have 4 rectangles (2 normal, 2 dashed-line rectangles). One of the dashed-line ones contain the above normal rectangle +2/3 of the other one and the second dashed-line rectangle includes the remaining 1/3 of the normal rectangle below. I should mention that I need to use nodes, because all the boxes (rectangles) must have a caption. Also, it is indifferent if the colors are as the picture or the rectangles are rounded.

Also, the exact place of captions is not that important to me. I just want them to be clear (which one relates to which rectangle). So, they can be centralized or left-adjusted or anything else.

7
  • 3
    Welcome to TeX.SX! Please don't post code fragments. Instead, put your fragments into a complete compilable document that shows the problem. – Alan Munn Aug 1 '17 at 21:25
  • 1
    Does the picture show what you want, or what you don't want? – Michael Palmer Aug 1 '17 at 21:48
  • @AlanMunn Sorry for my mistake. I changed the code. Now you can compile it. – user1419243 Aug 2 '17 at 7:20
  • @MichaelPalmer no, the code doesn't do what I want. I can just draw two separate rectangles, not overlapping ones. – user1419243 Aug 2 '17 at 7:20
  • @JohnKormylo I know. Thanks for reminding. I exactly need nodes. I'm not drawing pictures. As I said, I have just simplified the problem. All rectangles (outers and inners) must have a text inside. – user1419243 Aug 2 '17 at 7:21
2

Do you mean something like this?

outer and inner overlapping

You could do it entirely with nodes, but I think it is more straightforward to draw the boundaries of the outer boxes and place the texts separately in nodes without visible boundaries.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, calc}

\begin{document}
\begin{tikzpicture}
  [every node/.style={align=center, inner xsep=6mm, inner ysep=3mm, rounded corners}, very thick]
  \node (inner1) [draw] {Inner Text 1};
  \node (inner2) [draw, below=of inner1] {Inner Text 2};
  \node (outer) [fit=(inner1) (inner2)] {};
  \coordinate (o) at ($(inner2.north)!1/3!(inner2.south)$);
  \draw [blue, densely dashed, rounded corners] (outer.north west) rectangle (outer.east |- o) node [below=5mm of inner1, anchor=center] {Outer Text 1};
  \draw [green, densely dashed, rounded corners] node (outer2) [below=5mm of inner2, anchor=center] {Outer Text 2} (outer.west |- outer2.south) rectangle ([yshift=-\pgflinewidth]outer.east |- o);
\end{tikzpicture}
\end{document}
6
  • apparently you have crystal ball operational. mine is on vacation :( – Zarko Aug 2 '17 at 14:03
  • @Zarko :( Hope it has gone somewhere nice and is enjoying itself. I'm sure it will come back revitalised ;). – cfr Aug 2 '17 at 16:07
  • @cfr Could you please also tell me how I can have the lines which show the 1/3 and 2/3 of the box inside the rectangle (as shown in my picture of what I expect). Thanks. – user1419243 Aug 2 '17 at 19:30
  • @user1419243 Sorry, you've lost me. The lines cut through the lower box in just the same way in your picture of 'what you expect'. Do you mean the additional blue line in your picture? Oh, or do you mean that the lines should be 2/3 down rather than 1/3? Just change the 1/3 in my code to 2/3 in that case and the cut will split the bottom third rather than the top third. – cfr Aug 2 '17 at 21:48
  • @crf I mean exactly the blue lines. In fact I have two blue lines in the picture, but maybe one is not easily visible as it's hidden by the dashed-lines. – user1419243 Aug 3 '17 at 5:36
4

like this?

enter image description here

\documentclass[border=3pt, tikz]{standalone}
\usetikzlibrary{positioning, fit}

\begin{document}
    \begin{tikzpicture}[
    node distance = 3mm,
every node/.style = {rectangle, draw, rounded corners,
                     align=center, inner xsep=6mm, inner ysep=3mm}
                    ]
\node (inner1) [minimum width=32mm]                  {Inner Text};
\node (inner2) [minimum width=32mm, below=of inner1] {Inner Text 2};
%
\node[name=outer1, dashed, draw=blue, fit = (inner1) (inner2.north)] {};
\node[name=outer2, dashed, draw=blue, fit = (inner2.south west) (inner2.south east)] {};
    \end{tikzpicture}
\end{document}

Addendum: or this (as pointed me CarLaTeX)?

enter image description here

(your question about this is not clear)

\documentclass[border=3pt, tikz]{standalone}
\usetikzlibrary{positioning, fit}

\begin{document}
    \begin{tikzpicture}[
    node distance = 3mm,
every node/.style = {rectangle, draw, rounded corners,
                     align=center, inner xsep=6mm, inner ysep=3mm}
                    ]
\node (inner1) [minimum width=32mm]                  {Inner Text};
\node (inner2) [minimum width=32mm, below=of inner1] {Inner Text 2};
%
\node[name=outer1, dashed, draw=blue, fit = (inner1) (inner2),
      label=center:text of outer node] {};
    \end{tikzpicture}
\end{document}

Addendum (2): the last try ... guessing based on edited qurstion and comments below:

enter image description here

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

\begin{document}
    \begin{tikzpicture}[
node distance = 3mm,
 inbox/.style = {rectangle, draw, rounded corners,
                 minimum height=18mm, minimum width=32mm ,
                 align=center, inner xsep=6mm, inner ysep=3mm},
outbox/.style = {rectangle, draw=blue, densely dashed, rounded corners,
                 inner xsep=6mm, inner ysep=1mm}
                    ]
\node (inner1) [inbox,
                label={[name=TS] above:Training Set}]   {Data 1};
\node (inner2) [inbox, below=of inner1]                 {Data 2};
\node (test)   [above=1mm of inner2.south]              {Test Set}; 
%
\node (outer1) [outbox, fit = (TS) (inner1) ($(inner2.north)!0.25!(inner2.south)$),
      label=left:caption 1] {};
\node (outer2) [outbox, fit = ($(inner2.north)!0.75!(inner2.south)$) 
                              (inner2.south west) (inner2.south east),
      label=left:caption 2] {};
    \end{tikzpicture}
\end{document}
6
  • @CarLaTeX, i can't find this comment. i just reproduce given image. adding text in outer node in my mwe can be (as you probably know) tricky. if you like to be centered, than it should set as label positioning on node center. let waits what will say OP :) – Zarko Aug 2 '17 at 8:01
  • @CarLaTeX, i found it now and add addendum to my answer ... thank you to pointed me on it! – Zarko Aug 2 '17 at 8:19
  • @Zarko Thanks a lot for the codes. What I want is actually a combination of your two codes. The dashed rectangle must also have a caption. That's true. But the point is that it must include only part of the lower rectangle. In fact, I must have two normal rectangles and two dashed ones. One of the dashed one containes the above rectangle + 2/3 of the lower one and the other one most contain just the remaining 1/3 of the lower one. That is my aim. – user1419243 Aug 2 '17 at 11:17
  • @Zarko About the captions, I can't say that I want them centralized. What is important to me is that there must be obviously no overlap between them. So, maybe I can just have them on the left part of the dashed ones. I should play with the code. But I think that is not much difficult. Can't I do that just by setting the coordinates? Is it something that can't be easily changed in your code? – user1419243 Aug 2 '17 at 11:19
  • sorry,i not understand you well. you can add labels left or right of nodes, or in separate nodes positioning left of nodes. in both examples inner nodes not overlaps. i will try to make one more example asap. – Zarko Aug 2 '17 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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