3

I have the following tikz code:

\documentclass[crop,tikz]{standalone}


\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}

\usetikzlibrary{arrows,
    chains,
    decorations.markings,
    shadows, shapes.arrows,shapes, fit}

\begin{document}
\tikzset{%
sum/.style      = {draw, circle, node distance = 2cm}, % Adder
input/.style    = {coordinate}, % Input
output/.style   = {coordinate}, % Output
block/.style = { draw,
              thick,
              rectangle,
              minimum height = 2em,
              fill=white,
              align=center
},
wide block/.style = {
              block,
              minimum height = 3em,
              text width=2.5cm,
              minimum width = 8em,
},
dotted_block/.style={draw=black!20!white, line width=1pt, dash pattern=on 1pt off 4pt on 6pt off 4pt,
            inner sep=6mm, rectangle, rounded corners}
}
\newcommand{\suma}{\Large$+$}

\begin{tikzpicture}[auto, thick, node distance=2cm, >=triangle 45]
\draw
node at (0,0){}
node [input, name=input1] {} 
node [align=center, wide block, right = 1cm of input1] (inte2) {IEEE1}
node [align=center, wide block, right = 1cm of inte2] (inte3) {IEEE2}
node [align=center, wide block, right = 1cm of inte3] (inte4) {IEEE3}
node [sum, right = 1cm of inte4] (suma1) {\suma}
node [input, name=input2, above = 1cm of suma1] {} 
node [output, name=output1, right = 1cm of suma1] {};
\node [align=center, wide block, right = 0.5cm of output1] (glamor) {glamor};
\node[wide block, right = 15mm of glamor] (trainer) {trainer};
\node[block, below=10mm of glamor](M){giga};
\node[block, below=10mm of trainer](L){mn};
\node [dotted_block, fit = (inte2) (inte3)] (aa) {};
\node [dotted_block, fit = (inte4) (suma1)] (aa2) {};
\node [dotted_block, fit = (glamor) (trainer) (L) (M)] (aa3) {};

\node at (aa.north) [above, inner sep=3mm] {T1};
\node at (aa2.north) [above, inner sep=3mm] {T2};
\node at (aa3.north) [above, inner sep=3mm] {T3};

\draw[->](input1) -- node {kmm}(inte2);
\draw[->](inte2) -- node {kdd}(inte3);
\draw[->](inte3) -- node {dx}(inte4);
\draw[->](inte4) -- node {msg}(suma1);
\draw[->](input2) -- node {taco} (suma1);
\draw[<-](glamor.west) --node[above]{$y$} ++(-1.5,0);
\draw[->](glamor) -- node {dol} (trainer);
\draw[->](trainer.east) -- node[name=y]{kmm} ++ (2,0);
\draw[->,rounded corners](trainer.east) -- ++(1,0) |- (L);
\draw[->](L)--(M);
\draw[<-, rounded corners]([yshift=1mm]glamor.south west) 
       -- ++(-1,0) |- (M.west);
\end{tikzpicture}
\end{document}

Which created the following figure: Figure

How can I arrange the dashed rectangles T1, T2 and T3 to be symmetric as possible and contain all the blocks and arrows without overlaps, as there is now for T1 and T2? T3 should surround all the arrows that are currently outside.

The output should be like: enter image description here

1 Answer 1

2

Change inner xsep.

\documentclass[crop,tikz]{standalone}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}

\usetikzlibrary{arrows,
    chains,
    decorations.markings,
    shadows, shapes.arrows,shapes, fit}

\begin{document}
\tikzset{%
sum/.style      = {draw, circle, node distance = 2cm}, % Adder
input/.style    = {coordinate}, % Input
output/.style   = {coordinate}, % Output
block/.style = { draw,
              thick,
              rectangle,
              minimum height = 2em,
              fill=white,
              align=center
},
wide block/.style = {
              block,
              minimum height = 3em,
              text width=2.5cm,
              minimum width = 8em,
},
dotted_block/.style={draw=black!20!white, line width=1pt, dash pattern=on 1pt off 4pt on 6pt off 4pt,
            inner ysep=6mm,inner xsep=3mm, rectangle, rounded corners}
}
\newcommand{\suma}{\Large$+$}

\begin{tikzpicture}[auto, thick, node distance=2cm, >=triangle 45]
\draw
node at (0,0){}
node [input, name=input1] {} 
node [align=center, wide block, right = 1cm of input1] (inte2) {IEEE1}
node [align=center, wide block, right = 1cm of inte2] (inte3) {IEEE2}
node [align=center, wide block, right = 1cm of inte3] (inte4) {IEEE3}
node [sum, right = 1cm of inte4] (suma1) {\suma}
node [input, name=input2, above = 1cm of suma1] {} 
node [output, name=output1, right = 1cm of suma1] {};
\node [align=center, wide block, right = 0.5cm of output1] (glamor) {glamor};
\node[wide block, right = 15mm of glamor] (trainer) {trainer};
\node[block, below=10mm of glamor](M){giga};
\node[block, below=10mm of trainer](L){mn};
\node [dotted_block, fit = (inte2) (inte3)] (aa) {};
\node [dotted_block, fit = (inte4) (suma1)] (aa2) {};
\node [dotted_block, fit = (glamor) (trainer) (L) (M)] (aa3) {};

\node at (aa.north) [above, inner sep=3mm] {T1};
\node at (aa2.north) [above, inner sep=3mm] {T2};
\node at (aa3.north) [above, inner sep=3mm] {T3};

\draw[->](input1) -- node {kmm}(inte2);
\draw[->](inte2) -- node {kdd}(inte3);
\draw[->](inte3) -- node {dx}(inte4);
\draw[->](inte4) -- node {msg}(suma1);
\draw[->](input2) -- node {taco} (suma1);
\draw[<-](glamor.west) --node[above]{$y$} ++(-1.5,0);
\draw[->](glamor) -- node {dol} (trainer);
\draw[->](trainer.east) -- node[name=y]{kmm} ++ (2,0);
\draw[->,rounded corners](trainer.east) -- ++(1,0) |- (L);
\draw[->](L)--(M);
\draw[<-, rounded corners]([yshift=1mm]glamor.south west) 
       -- ++(-1,0) |- (M.west);
\end{tikzpicture}
\end{document}

enter image description here

Here is another version with individual inner xseps and an xshift.

\documentclass[crop,tikz]{standalone}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}

\usetikzlibrary{arrows,
    chains,
    decorations.markings,
    shadows, shapes.arrows,shapes, fit}

\begin{document}
\tikzset{%
sum/.style      = {draw, circle, node distance = 2cm}, % Adder
input/.style    = {coordinate}, % Input
output/.style   = {coordinate}, % Output
block/.style = { draw,
              thick,
              rectangle,
              minimum height = 2em,
              fill=white,
              align=center
},
wide block/.style = {
              block,
              minimum height = 3em,
              text width=2.5cm,
              minimum width = 8em,
},
dotted_block/.style={draw=black!20!white, line width=1pt, dash pattern=on 1pt off 4pt on 6pt off 4pt,
            inner ysep=6mm,inner xsep=4mm, rectangle, rounded corners}
}
\newcommand{\suma}{\Large$+$}

\begin{tikzpicture}[auto, thick, node distance=2cm, >=triangle 45]
\draw
node at (0,0){}
node [input, name=input1] {} 
node [align=center, wide block, right = 1cm of input1] (inte2) {IEEE1}
node [align=center, wide block, right = 1cm of inte2] (inte3) {IEEE2}
node [align=center, wide block, right = 1cm of inte3] (inte4) {IEEE3}
node [sum, right = 1cm of inte4] (suma1) {\suma}
node [input, name=input2, above = 1cm of suma1] {} 
node [output, name=output1, right = 1cm of suma1] {};
\node [align=center, wide block, right = 0.5cm of output1] (glamor) {glamor};
\node[wide block, right = 15mm of glamor] (trainer) {trainer};
\node[block, below=10mm of glamor](M){giga};
\node[block, below=10mm of trainer](L){mn};
\node [dotted_block, fit = (inte2) (inte3)] (aa) {};
\node [dotted_block, fit = (inte4) (suma1)] (aa2) {};
\node [dotted_block, fit = (glamor) (trainer) (L) (M),inner xsep=9mm,xshift=4mm] (aa3) {};

\node at (aa.north) [above, inner sep=3mm] {T1};
\node at (aa2.north) [above, inner sep=3mm] {T2};
\node at (aa3.north) [above, inner sep=3mm] {T3};

\draw[->](input1) -- node {kmm}(inte2);
\draw[->](inte2) -- node {kdd}(inte3);
\draw[->](inte3) -- node {dx}(inte4);
\draw[->](inte4) -- node {msg}(suma1);
\draw[->](input2) -- node {taco} (suma1);
\draw[<-](glamor.west) --node[above]{$y$} ++(-1.5,0);
\draw[->](glamor) -- node {dol} (trainer);
\draw[->](trainer.east) -- node[name=y]{kmm} ++ (2,0);
\draw[->,rounded corners](trainer.east) -- ++(1,0) |- (L);
\draw[->](L)--(M);
\draw[<-, rounded corners]([yshift=1mm]glamor.south west) 
       -- ++(-1,0) |- (M.west);
\end{tikzpicture}
\end{document}

enter image description here

Another possibility is to use some auxiliary nodes as landmarks and fit these.

\documentclass[crop,tikz]{standalone}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}

\usetikzlibrary{arrows,
    chains,
    decorations.markings,
    shadows, shapes.arrows,shapes, fit}

\begin{document}
\tikzset{%
sum/.style      = {draw, circle, node distance = 2cm}, % Adder
input/.style    = {coordinate}, % Input
output/.style   = {coordinate}, % Output
block/.style = { draw,
              thick,
              rectangle,
              minimum height = 2em,
              fill=white,
              align=center
},
wide block/.style = {
              block,
              minimum height = 3em,
              text width=2.5cm,
              minimum width = 8em,
},
dotted_block/.style={draw=black!20!white, line width=1pt, dash pattern=on 1pt off 4pt on 6pt off 4pt,
            inner ysep=6mm,inner xsep=1mm, rectangle, rounded corners}
}
\newcommand{\suma}{\Large$+$}

\begin{tikzpicture}[auto, thick, node distance=2cm, >=triangle 45]
\draw
node at (0,0){}
node [input, name=input1] {} 
node [align=center, wide block, right = 1cm of input1] (inte2) {IEEE1}
node [align=center, wide block, right = 1cm of inte2] (inte3) {IEEE2}
node [align=center, wide block, right = 1cm of inte3] (inte4) {IEEE3}
node [sum, right = 1cm of inte4] (suma1) {\suma}
node [input, name=input2, above = 1cm of suma1] {} 
node [output, name=output1, right = 1cm of suma1] {};
\node [align=center, wide block, right = 0.5cm of output1] (glamor) {glamor};
\node[wide block, right = 15mm of glamor] (trainer) {trainer};
\node[block, below=10mm of glamor](M){giga};
\node[block, below=10mm of trainer](L){mn};


\draw[->](input1) -- node (kmm1) {kmm}(inte2);
\draw[->](inte2) -- node {kdd}(inte3);
\draw[->](inte3) -- node (dx) {dx}(inte4);
\draw[->](inte4) -- node {msg}(suma1);
\draw[->](input2) -- node {taco} (suma1);
\draw[<-](glamor.west) --node[above]{$y$} ++(-1.5,0);
\draw[->](glamor) -- node {dol} (trainer);
\draw[->](trainer.east) -- node[name=y]{kmm} ++ (2,0);
\draw[->,rounded corners](trainer.east) -- ++(1,0) |- (L);
\draw[->](L)--(M);
\draw[<-, rounded corners]([yshift=1mm]glamor.south west) 
       -- ++(-1,0) coordinate[left=1mm](aux) |- (M.west);

\node [dotted_block, fit =(kmm1.center) (inte2) (inte3) (dx.west)] (aa) {};
\node [dotted_block, fit = (inte4) (suma1) (dx.east)] (aa2) {};
\node [dotted_block, fit = (glamor) (trainer) (L) (M) (y) (aux)] (aa3) {};
\node at (aa.north) [above, inner sep=3mm] {T1};
\node at (aa2.north) [above, inner sep=3mm] {T2};
\node at (aa3.north) [above, inner sep=3mm] {T3};

\end{tikzpicture}
\end{document}

enter image description here

10
  • How can I make the T3 dashed lines to surround also the arrows?
    – Codevan
    Commented Apr 21, 2019 at 13:31
  • 1
    @Codevan Which arrows? Do you want to also fit the arrow on the right or the complete arrow going from giga to glamore?
    – user121799
    Commented Apr 21, 2019 at 13:42
  • Both that you mentioned, and also align T1 and T2 to have the same size as T3.
    – Codevan
    Commented Apr 21, 2019 at 13:50
  • @Codevan Do you want both arrows completely in the dashed box?
    – user121799
    Commented Apr 21, 2019 at 13:51
  • 1
    @Codevan I added an alternative that does not require you to tune xshifts.
    – user121799
    Commented Apr 21, 2019 at 14:31

You must log in to answer this question.

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