7

I am trying to draw block diagram as attached in the figure. I tried to draw and don't know how to add Arrows and label the bigbox I used. Can anyone help to draw such block diagram either completing from the existing code or by new way?enter image description here

I tried to draw by following code:

    \begin{figure*}
\begin{center}
\begin{tikzpicture}[shorten >=1pt,node distance=3.7cm,>=stealth',bend angle=45]
\tikzstyle{block} = [rectangle, draw=black, thick, text width=0.5em, text centered, minimum height=1em]
\tikzstyle{block1}=[rectangle, draw=black, thick, text width=2em, text centered,minimum height=3em]
\tikzstyle{block2}=[rectangle, draw=black, thick, text width=4em, text centered,minimum height=2em]
\tikzstyle{block3}=[rectangle, draw=black, thick, text width=8em, text centered,minimum height=5em]
\tikzstyle{bigbox} = [draw=black,thick, rectangle]
\tikzstyle{triple}=[draw, anchor=text, thick, rectangle split,rectangle split parts=3]
\tikzstyle{double}=[draw, anchor=text, thick, rectangle split,rectangle split parts=2]
%\tikzstyle{textbox} = {draw, fill=white, thick,text=black}
\node[block] (A) {};
\node[block] (B) [below=0.2cm of A] {}; 
\node[block] (C) [below=0.2cm of B] {}; 
\node[block] (D) [below=0.2cm of C] {}; 
\node[block] (E) [below=0.2cm of D] {}; 
\node[block] (F) [below=0.2cm of E] {}; 
\node[block] (G) [right=0.4cm of C] {};
\node[block] (H) [right=0.1cm of G] {};
\node[block] (I) [right=0.1cm of H] {};
\node[block] (J) [right=0.3cm of I] {};
\node[block] (K) [right=0.1cm of J] {};
\node[block] (L) [right=0.1cm of K] {};

\node[block] (P) [right=2cm of L] {};
\node[block] (Q) [right=0.1cm of P] {};
\node[block] (R) [right=0.1cm of Q] {};
\node[block] (S) [right=0.3cm of R] {};
\node[block] (T) [right=0.1cm of S] {};
\node[block] (U) [right=0.1cm of T] {};
\node[block] (X) [right=0.3cm of U] {};
\node[block] (Y) [above=0.2cm of X] {};
\node[block] (Z) [above=0.2cm of Y] {};
\node[block] (Aa) [below=0.2cm of X] {};
\node[block] (Ab) [below=0.2cm of Aa] {};
\node[block] (Ac) [below=0.2cm of Ab] {};

    \begin{pgfonlayer}{background}
  \node[bigbox] (M) [fit = (G) (H) (I)] {};
     \node[bigbox] (N) [fit = (J) (K) (L)] {};
     \node[bigbox] (V) [fit = (P) (Q) (R)] {};
     \node[bigbox] (W) [fit = (S) (T) (U)] {};

    \node[bigbox] (O) [fit = (A) (B) (C) (D) (E) (F) (G) (H) (I) (J) (K) (L) (N)] {};
    \node[bigbox] (Ad) [fit = (P) (Q) (R) (S) (T) (U) (V) (W) (Aa) (Ac) (Z)] {};
\end{pgfonlayer}
    \end{tikzpicture}
\caption{Proposed Framework} \label{fig1}
\end{center}
\end{figure*}
3
  • You can highlight code in your post using back-ticks. To highlight code-blocks, either indent them by four spaces or use the {} on the gui.
    – user30471
    Apr 25, 2017 at 5:21
  • 1
    Welcome to TeX.SX! Can you please expand the code snippets that you have posted to a full minimal working example. It is much easier to help you you if we can start with some compilable code that illustrates your problem. A MWE should compile and be as small as possible to demonstrate your problem.
    – user30471
    Apr 25, 2017 at 5:21
  • 1
    You should read: tex.stackexchange.com/questions/52372/…
    – Ignasi
    Apr 25, 2017 at 7:27

3 Answers 3

5

Although jakun already provided a solution, this is an alternative one.

Source and Destination can be added as labels of largest fit nodes:

  \node[bigbox, label=source] (O) [fit = (A) (F) (N)] {};

(I've simplified fit parameter to only include significant nodes and not all of them)

And as an alternative to jakun's transform canvas (which I didn't know) you could use:

\draw[<-] ([yshift=8mm]O.south east) coordinate (aux) -- node[below] {Ack} (aux-|Ad.west);

or with calc tikzlibrary:

\draw[->] ($(O.north east)!.2!(O.south east)$) -- ($(Ad.north west)!.2!(Ad.south west)$);

The complete code could be:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning, backgrounds, fit}
\usepackage{lmodern}

\begin{document}

    \begin{figure*}
\begin{center}
\begin{tikzpicture}[shorten >=1pt,node distance=3.7cm,>=stealth',bend angle=45, font=\sffamily]
\tikzstyle{block} = [rectangle, draw=black, thick, text width=0.5em, text centered, minimum height=1em]
\tikzstyle{block1}=[rectangle, draw=black, thick, text width=2em, text centered,minimum height=3em]
\tikzstyle{block2}=[rectangle, draw=black, thick, text width=4em, text centered,minimum height=2em]
\tikzstyle{block3}=[rectangle, draw=black, thick, text width=8em, text centered,minimum height=5em]
\tikzstyle{bigbox} = [draw=black,thick, rectangle]
\tikzstyle{triple}=[draw, anchor=text, thick, rectangle split,rectangle split parts=3]
\tikzstyle{double}=[draw, anchor=text, thick, rectangle split,rectangle split parts=2]
%\tikzstyle{textbox} = {draw, fill=white, thick,text=black}
\node[block] (A) {};
\node[block] (B) [below=0.2cm of A] {}; 
\node[block] (C) [below=0.2cm of B] {}; 
\node[block] (D) [below=0.2cm of C] {}; 
\node[block] (E) [below=0.2cm of D] {}; 
\node[block] (F) [below=0.2cm of E] {}; 
\node[block] (G) [right=0.4cm of C] {};
\node[block] (H) [right=0.1cm of G] {};
\node[block] (I) [right=0.1cm of H] {};
\node[block] (J) [right=0.3cm of I] {};
\node[block] (K) [right=0.1cm of J] {};
\node[block] (L) [right=0.1cm of K] {};

\node[block] (P) [right=2cm of L] {};
\node[block] (Q) [right=0.1cm of P] {};
\node[block] (R) [right=0.1cm of Q] {};
\node[block] (S) [right=0.3cm of R] {};
\node[block] (T) [right=0.1cm of S] {};
\node[block] (U) [right=0.1cm of T] {};
\node[block] (X) [right=0.3cm of U] {};
\node[block] (Y) [above=0.2cm of X] {};
\node[block] (Z) [above=0.2cm of Y] {};
\node[block] (Aa) [below=0.2cm of X] {};
\node[block] (Ab) [below=0.2cm of Aa] {};
\node[block] (Ac) [below=0.2cm of Ab] {};

\begin{pgfonlayer}{background}
  \node[bigbox] (M) [fit = (G) (H) (I)] {};     
  \node[bigbox] (N) [fit = (J) (K) (L)] {};
  \node[bigbox] (V) [fit = (P) (Q) (R)] {};
  \node[bigbox] (W) [fit = (S) (T) (U)] {};

  \node[bigbox, label=source] (O) [fit = (A) (F) (N)] {};
  \node[bigbox, label=destination] (Ad) [fit = (Z) (Ac) (V)] {};
\end{pgfonlayer}
\path (M.south) -- node[below] {Packets} (N.south);
\path (V.south) -- node[below] {Packets} (W.south);

\draw[->] ([yshift=-8mm]O.north east) coordinate (aux) -- (aux-|Ad.west);
\draw[<-] ([yshift=8mm]O.south east) coordinate (aux) -- node[below] {Ack} (aux-|Ad.west);
\end{tikzpicture}
\caption{Proposed Framework} \label{fig1}
\end{center}
\end{figure*}
\end{document}

enter image description here

Update: The code could be simplified with the help of some matrix nodes:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning, fit, matrix}
\usepackage{lmodern}

\begin{document}

\begin{figure*}
\begin{center}
\begin{tikzpicture}[%
    shorten >=1pt,
    shorten <=1pt,
    >=stealth',
    font=\sffamily,
    block/.style = {rectangle, black, thick, text width=0.5em, text centered, minimum height=1em},
    packet/.style={draw, thick, matrix of nodes, nodes in empty cells, nodes={block, draw}},
    bigbox/.style={rectangle, draw, thick}
    ]

\matrix (A1) [packet, draw=none, row sep=2mm]{ \\ \\ \\ \\ \\ \\ };
\matrix (B1) [packet, column sep=2mm, right=3mm of A1]{ & & \\};
\matrix (C1) [packet, column sep=2mm, right=1mm of B1]{ & & \\};
\node[bigbox, label=Source] (D1) [fit = (A1) (C1)] {};

\matrix (C2) [packet, column sep=2mm, right=2cm of C1]{ & & \\};
\matrix (B2) [packet, column sep=2mm, right=1mm of C2]{ & & \\};
\matrix (A2) [packet, draw=none, row sep=2mm, right=3mm of B2]{ \\ \\ \\ \\ \\ \\ };
\node[bigbox, label=Destination] (D2) [fit = (A2) (C2)] {};

\path (B1.south) -- node[below] {Packets} (C1.south);
\path (B2.south) -- node[below] {Packets} (C2.south);

\draw[->, thick] ([yshift=-8mm]D1.north east) coordinate (aux) -- (aux-|D2.west);
\draw[<-, thick] ([yshift=8mm]D1.south east) coordinate (aux) -- node[below] {Ack} (aux-|D2.west);
\end{tikzpicture}
\caption{Proposed Framework} \label{fig1}
\end{center}
\end{figure*}
\end{document}
4

Add the following to your code:

% arrows
\draw[->, transform canvas={yshift=-1cm}] (O.north east) -- (Ad.north west);
\draw[<-, transform canvas={yshift=1cm}] (O.south east) -- node[below]{ACK} (Ad.south west);
% invisible coordinates to position the labels
\node (channel-y-position) [below=0pt of O] {\strut};
\path (O) -- coordinate (channel-x-position) (Ad);
% labels
\node[above=0pt of O] {Source};
\node[above=0pt of Ad] {Destination};
\node at (channel-x-position |- channel-y-position) {Channel};

I would use loops:

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

\begin{document}
\begin{tikzpicture}%[shorten >=1pt,node distance=3.7cm,>=stealth',bend angle=45]
    \tikzstyle{block} = [rectangle, draw=black, thick, text width=0.5em, text centered, minimum height=1em]
    \tikzstyle{block1}=[rectangle, draw=black, thick, text width=2em, text centered,minimum height=3em]
    \tikzstyle{block2}=[rectangle, draw=black, thick, text width=4em, text centered,minimum height=2em]
    \tikzstyle{block3}=[rectangle, draw=black, thick, text width=8em, text centered,minimum height=5em]
    \tikzstyle{bigbox} = [draw=black,thick, rectangle]
    \tikzstyle{triple}=[draw, anchor=text, thick, rectangle split,rectangle split parts=3]
    \tikzstyle{double}=[draw, anchor=text, thick, rectangle split,rectangle split parts=2]
    %\tikzstyle{textbox} = {draw, fill=white, thick,text=black}

    \newcommand{\numVer}{6}
    \newcommand{\numHor}{3}
    \newcommand{\numHorGroups}{2}

    % ------ source ------
    % vertical
    \node[block] (source-ver-1) {};
    \foreach \i [remember=\i as \last (initially 1)] in {2,...,\numVer} {
        \node[block] (source-ver-\i) [below=0.2cm of source-ver-\last] {}; 
    }

    % horizontal
    \coordinate[right=.1cm of source-ver-3] (source-hor-group-0);
    \foreach \group [remember=\group as \lastGroup (initially 0)] in {1,...,\numHorGroups} {
        \node[block] (source-hor-\group-1) [right=0.3cm of source-hor-group-\lastGroup] {};
        \foreach \i [remember=\i as \last (initially 1)] in {2,...,\numHor} {
            \node[block] (source-hor-\group-\i) [right=.1cm of source-hor-\group-\last] {}; 
        }
        \node[bigbox] (source-hor-group-\group) [fit = (source-hor-\group-1) (source-hor-\group-\numHor), label=below:Packet~\group] {};
    }

    % frame
    \node[bigbox, label=above:Source] (source) [fit = (source-ver-1) (source-ver-\numVer) (source-hor-group-\numHorGroups)] {};


    % ------ destination ------
    % horizontal
    \coordinate[right=2cm of source-hor-\numHorGroups-\numHor] (dest-hor-group-0);
    \foreach \group [remember=\group as \lastGroup (initially 0)] in {1,...,\numHorGroups} {
        \node[block] (dest-hor-\group-1) [right=0.3cm of dest-hor-group-\lastGroup] {};
        \foreach \i [remember=\i as \last (initially 1)] in {2,...,\numHor} {
            \node[block] (dest-hor-\group-\i) [right=.1cm of dest-hor-\group-\last] {}; 
        }
        \node[bigbox] (dest-hor-group-\group) [fit = (dest-hor-\group-1) (dest-hor-\group-\numHor), label=below:Packet~\group] {};
    }

    % vertical
    \coordinate[right=.3cm of dest-hor-group-\numHorGroups] (dest-ver-west);
    \node[block] (dest-ver-1) at (dest-ver-west |- source-ver-1) [anchor=west] {};
    \foreach \i [remember=\i as \last (initially 1)] in {2,...,\numVer} {
        \node[block] (dest-ver-\i) [below=0.2cm of dest-ver-\last] {}; 
    }

    % frame
    \node[bigbox, label=above:Destination] (dest) [fit = (dest-ver-1) (dest-ver-\numVer) (dest-hor-group-1)] {};

    % ------ arrows ------
    % arrows
    \draw[->, transform canvas={yshift=-1cm}] (source.north east) -- (dest.north west);
    \draw[<-, transform canvas={yshift=1cm}] (source.south east) -- node[below]{ACK} (dest.south west);
    % invisible coordinates to position the labels
    \node (channel-y-position) [below=0pt of source] {\strut};
    \coordinate (channel-x-position) at ($(source.east)!.5!(dest.west)$);
    % labels
    \node at (channel-x-position |- channel-y-position) {Channel};
\end{tikzpicture}
\end{document}

screenshot

2

I canged some parts of your code, e.g. to get more square nodes and to line up the output and input buffer in the center of the packets list. By uing calc library as well as -|, you can manipulate the coordinates to where yo want. I have not cared much about the fonts.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,fit,calc}
\begin{document}

\begin{tikzpicture}[shorten >=1pt,node distance=3.7cm,>=stealth',bend angle=45]
  % \tikzstyle{block} = [rectangle, draw=black, thick, text width=0.5em, text centered, minimum height=1em]
  \tikzstyle{block} = [rectangle, draw=black, thick, inner sep=0pt,minimum width=1em, minimum height=1em]
  % \tikzstyle{block1}=[rectangle, draw=black, thick, text width=2em, text centered,minimum height=3em]
  % \tikzstyle{block2}=[rectangle, draw=black, thick, text width=4em, text centered,minimum height=2em]
  % \tikzstyle{block3}=[rectangle, draw=black, thick, text width=8em, text centered,minimum height=5em]
  \tikzstyle{bigbox} = [draw=black,thick, rectangle]
  % \tikzstyle{triple}=[draw, anchor=text, thick, rectangle split,rectangle split parts=3]
  % \tikzstyle{double}=[draw, anchor=text, thick, rectangle split,rectangle split parts=2]
  % \tikzstyle{textbox} = {draw, fill=white, thick,text=black}
  \node[block] (A) {};
  \node[block] (B) [below=0.2cm of A] {}; 
  \node[block] (C) [below=0.2cm of B] {}; 
  \node[block] (D) [below=0.2cm of C] {}; 
  \node[block] (E) [below=0.2cm of D] {}; 
  \node[block] (F) [below=0.2cm of E] {}; 
  \node[block] (G) [right=0.4cm of {$(C.south east)!0.5!(D.north east)$}] {};
  \node[block] (H) [right=0.1cm of G] {};
  \node[block] (I) [right=0.1cm of H] {};
  \node[block] (J) [right=0.3cm of I] {};
  \node[block] (K) [right=0.1cm of J] {};
  \node[block] (L) [right=0.1cm of K] {};

  \node[block] (P) [right=2cm of L] {};
  \node[block] (Q) [right=0.1cm of P] {};
  \node[block] (R) [right=0.1cm of Q] {};
  \node[block] (S) [right=0.3cm of R] {};
  \node[block] (T) [right=0.1cm of S] {};
  \node[block] (U) [right=0.1cm of T] {};
  \node[block] (X) [right=0.3cm of {U.east |- C}] {};
  \node[block] (Y) [above=0.2cm of X] {};
  \node[block] (Z) [above=0.2cm of Y] {};
  \node[block] (Aa) [below=0.2cm of X] {};
  \node[block] (Ab) [below=0.2cm of Aa] {};
  \node[block] (Ac) [below=0.2cm of Ab] {};

  % \begin{pgfonlayer}{background}
  \node[bigbox] (M) [fit = (G) (H) (I)] {};
  \node[bigbox] (N) [fit = (J) (K) (L)] {};
  \node[bigbox] (V) [fit = (P) (Q) (R)] {};
  \node[bigbox] (W) [fit = (S) (T) (U)] {};

  \node[bigbox,label=above:Source] (O) [fit = (A) (B) (C) (D) (E) (F) (G) (H) (I) (J) (K) (L) (N)] {};
  \node[bigbox,label=above:Destination] (Ad) [fit = (P) (Q) (R) (S) (T) (U) (V) (W) (Aa) (Ac) (Z)] {};
  % \end{pgfonlayer}
  \draw[->](O.30)--(Ad.180 |- O.30);
  \draw[<-](O.-30)--(Ad.180 |- O.-30)node[pos=0.5,below]{ACK};
  \node[below=1em] at ($(O.south east)!0.5!(Ad.south west)$){CHANNEL};
  \node[below] at ($(M.south)!0.5!(N.south)$){Packets};
  \node[below] at ($(V.south)!0.5!(W.south)$){Packets};
\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 .