5

I try to draw a diagram similar tp this one:

desired

What I currently have is this:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=2]
\tikzstyle{atomic} = [draw, thick,minimum width=1.5cm,minimum height=1.5cm]
\tikzstyle{io} = [draw, thick,circle]
\node (a) at (4,2) [atomic] {A};
\node (b) at (6,2) [atomic] {B};
\node[io] (zb) at (5,2){$Z_B$};
\draw[-latex,thick](a)
edge 
node[pos=0,above left]{$Y_A$}
(zb);

\draw[-latex,thick]
(zb)
edge
node[pos=1,above right]{$X_B$}
(b);
\end{tikzpicture}


\end{document}

current

Is there a simpler way to arrange the boxes and circles? Currently I try to find the correct coordinates manually.

How can I have the arrows make the 90 degree turns? How can I nest the smaller boxes into the big one and annotated the entry and exit arrows?

5

Something like this: enter image description here

Code in pure TikZ:

\documentclass[border=3mm,tikz,preview]{standalone}
    \usetikzlibrary{arrows.meta,%
                    backgrounds,%
                    calc,%
                    fit,%
                    positioning,
                    scopes,shadows}

\makeatletter
\def\tikzsavelastnodename#1{\let#1=\tikz@last@fig@name}
\makeatother

    \begin{document}
%---------------------------------------------------------------%
    \begin{tikzpicture}[
            > = {Triangle[]},
node distance = 2mm and 7mm,
% for labels inside node shape
inlabel/.style args =
    {#1:#2}{append after command=
            {node[inner sep=1mm,anchor=#1] at (\tikzsavednodename.#1) {#2}}
            },
% schemas' blocks
        atomic/.style = {draw, thick, fill=white, 
                         minimum size=1.5cm, drop shadow,
                         append after command= {\pgfextra{\tikzsavelastnodename\tikzsavednodename}},#1
                        },
            io/.style = {draw, thick, fill=white, circle, drop shadow},
                    ]
%---
\node[atomic,
      inlabel=west:$X_A$,
      inlabel=east:$Y_A$,
      inlabel=south:$A$,
      ]                         (a)     {};
\node[io,below right=of a.south east]   (zn)    {$Z_N$};
\node[atomic,
      inlabel=west:$X_A$,
      inlabel=east:$Y_A$,
      inlabel=south:$B$,
      below left=of zn]         (b)     {};
\node[io, left=of a]            (za)    {$Z_A$};
\node[io, left=of b]            (zb)    {$Z_B$};
%
\coordinate[left=of za.150]     (xn');
\coordinate[left=of xn']        (xn);
\coordinate[left=4mm of zn.150] (zn');
\coordinate[right=of zn]        (yn);
% lines connecting block A
\draw[->] (xn) node[left] {$X_N$} -- (za.150);
\draw[->] (za) edge (a);
\draw[->] (a.east) -| (zn') -| (xn' |- za.210) -- (za.210);
\draw[->] (zn') -- (zn.150); 
% lines connecting block B
\draw[->] (zb) -- (b);
\draw[->] (b)  -| (zn' |- zn.210) -- (zn.210);
\draw[->] (xn' |- zn') |- (zb);
\draw[->] (zn) -- (yn) node[right] {$Y_N$};
% outer block (N)
\scoped[on background layer]
    \node[atomic,inner xsep=0mm,
          fit=(xn) (a) (yn) (b),
          inlabel=south west:$N$] {};
        \end{tikzpicture}
%---------------------------------------------------------------%
    \end{document}

For drawing lines I explicit defined a set of coordinates. Fro 90 degree turn exist syntax |- and -|. As can you see in MWE, both I used extensively used in above code for drawing of lines as well for determined some impliticit determined coordinated (for example (xn' |- zn') for start of line to node zb.

  • Looks great! What does the syntax za.210 mean? – m.s. Jul 8 '15 at 9:02
  • 1
    @m.s., za is name of node, number 210 is angle of straight line through shape center point. On cross of it with shape border is point -- anchor -- to which someone like to draw a line or star with it drawing. – Zarko Jul 8 '15 at 10:31
  • @m.s. an addendum to previous comment: ``za.0` is equivalent to za.east, za.45 is equivalent for za.north east etc. With other words, angles 0, 45, 90, 135, 180 225, 270 and 315 define the same points on shape border as east˛ north east, north, north west etc extensions to node names. – Zarko Jul 8 '15 at 10:46
  • Do you know where I can find this in the Tikz manual? – m.s. Jul 8 '15 at 10:48
  • See examples in shape libraries (chapter 67, pp. 683 in my CVS version of manual). Well, there this not explained on such a way as I do in comment above, but you can easy figured out the idea. Unfortunately, the TikZ manual is really huge in it is easy to lost in it. – Zarko Jul 8 '15 at 10:57

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.