3

I have been trying to create my second Tikz model based on TikZ: Diagram of a perceptron. I have manage to modify it based on my beginners knowledge and experimentation but the part that I am missing and I can not figure out how to make the bullets. I am trying to make the distance smaller but there is not affect. I tried with distance node = 1 em but not successfully for the moment. Is there a possible solution to my problem? A sample of the output is provided.Output Any suggestions are appreciated.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc} % braces {}
\usetikzlibrary{shapes,arrows,positioning}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}

\tikzset{
 block/.style={
  draw, 
  rectangle, 
  minimum height=2em, 
  minimum width=5em,
 },
 sum/.style={
  draw, 
  circle, 
  minimum size=2em
 },
 input/.style={coordinate}, 
 output/.style={coordinate},
 mytext/.style={
  draw,
  text depth=4pt,
  text height=10pt
 }
}

\begin{figure}[!ht]
\begin{center}
\makebox[\textwidth][c]{%
\begin{tikzpicture}[auto,>=latex']

% Blocks
\node[input, name = input] {};
\node[sum, right = of input, node distance = 1em] (sum) {MP};
\node[block, right of = sum, node distance = 6.5em] (stream) {Stream $2$};
\node[sum, right = of stream, node distance = 1em] (filter) {$F_2$};
\node[sum, above = of sum, node distance = 5em] (sum_2) {MP};
\node[block, right of = sum_2, node distance = 6.5em] (stream_2) {Stream$1$};
\node[sum, right = of stream_2, node distance = 1em] (filter_2) {$F_1$};

% Bullets
\node[below of = sum, node distance = 3em] (dot) {$\bullet$} -- (dot);
\node[below of = dot, node distance = 1em] (dot_2) {$\bullet$} -- (dot_2);
\node[below of = dot_2, node distance = 1em] (dot_3) {$\bullet$} -- (dot_3);
\node[below of = stream, node distance = 3em] (dot_4) {$\bullet$} -- (dot_4);
\node[below of = dot_4, node distance = 1em] (dot_5) {$\bullet$} -- (dot_5);
\node[below of = dot_5, node distance = 1em] (dot_6) {$\bullet$} -- (dot_6);
\node[below of = filter, node distance = 3em] (dot_7) {$\bullet$} -- (dot_7);
\node[below of = dot_7, node distance = 1em] (dot_8) {$\bullet$} -- (dot_8);
\node[below of = dot_8, node distance = 1em] (dot_9) {$\bullet$} -- (dot_9);

% Blocks
\node[input, name = input_n] {};
\node[sum, below = of dot_3, node distance = 1em] (sum_n) {MP};
\node[block, right of = sum_n, node distance = 6.5em] (stream_n) {Stream $n$};
\node[sum, right = of stream_n, node distance = 1em] (filter_n) {$F_n$};

% Sum
\node[sum, right = of filter, node distance = 3em] (total) {$\sum$};

% Oneway delay
\node[block, right of = total, node distance = 7.5em] (delay) {One Way Delay};
\node[block, right of = delay, node distance = 15em] (segments) {$MP_1$ $|$ $Payload_1$ $\dots$ $MP_n$ $|$ $Payload_n$};
\node[output,right = of segments] (output) {};

% Inputs
\node[input,left = of sum_2] (output_2) {};
\node[input,left = of sum_n] (output_n) {};

% Lines Center Block
\draw[->] (input) -- node [name = begging] {$IN_2$} (sum);
\draw[->] (sum) -- node {} (stream);
\draw[->] (stream) -- node {} (filter);
\draw[->] (filter) -- node {} (total);
\draw[->] (total) -- node {} (delay);
\draw[->] (delay) -- node {} (segments);
\draw[->] (segments) -- node {Data} (output);

% Lines Above Center Block
\draw[->] (sum_2) -- node {} (stream_2);
\draw[->] (stream_2) -- node {} (filter_2);
\draw[->] (filter_2) -- node {} (total);

% Lines Below Center Block
\draw[->] (sum_n) -- node {} (stream_n);
\draw[->] (stream_n) -- node {} (filter_n);
\draw[->] (filter_n) -- node {} (total);

% Input Lines
\draw[->] (output_2) -- node {$IN_1$} (sum_2);
\draw[->] (output_n) -- node {$IN_n$} (sum_n);

\end{tikzpicture} }% End of makebox
\caption{New Tikz}
\label{fig:tikz }
\end{center}
\end{figure}
\end{document}

2 Answers 2

2

I'd sugget you a different approach that will keep a consistent spacing between the layers:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc} % braces {}
\usetikzlibrary{shapes,arrows,positioning}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}

\tikzset{
 block/.style={
  draw, 
  rectangle, 
  minimum height=2em, 
  minimum width=5em,
 },
 sum/.style={
  draw, 
  circle, 
  minimum size=2em
 },
 input/.style={coordinate}, 
 output/.style={coordinate},
 mytext/.style={
  draw,
  text depth=4pt,
  text height=10pt
 }
}

\begin{figure}[!ht]
\begin{center}
\makebox[\textwidth][c]{%
\begin{tikzpicture}[auto,>=latex']

% Blocks
\node[input, name = input] {};
\node[sum, right = of input, node distance = 1em] (sum) {MP};
\node[block, right of = sum, node distance = 6.5em] (stream) {Stream $2$};
\node[sum, right = of stream, node distance = 1em] (filter) {$F_2$};
\node[sum, above = of sum, node distance = 5em] (sum_2) {MP};
\node[block, right of = sum_2, node distance = 6.5em] (stream_2) {Stream$1$};
\node[sum, right = of stream_2, node distance = 1em] (filter_2) {$F_1$};


% Blocks
\node[input, name = input_n] {};
\node[sum, below = of sum, node distance = 1em] (sum_n) {MP};
\node[block, right of = sum_n, node distance = 6.5em] (stream_n) {Stream $n$};
\node[sum, right = of stream_n, node distance = 1em] (filter_n) {$F_n$};

% Bullets
\foreach \Nodo in {sum,stream,filter}
{
  \node[rotate=90,font=\footnotesize] (dot) 
    at ( $ (\Nodo)!0.5!(\Nodo_n) $ ) {$\bullet\bullet\bullet$};
}

% Sum
\node[sum, right = of filter, node distance = 3em] (total) {$\sum$};

% Oneway delay
\node[block, right of = total, node distance = 7.5em] (delay) {One Way Delay};
\node[block, right of = delay, node distance = 15em] (segments) {$MP_1$ $|$ $Payload_1$ $\dots$ $MP_n$ $|$ $Payload_n$};
\node[output,right = of segments] (output) {};

% Inputs
\node[input,left = of sum_2] (output_2) {};
\node[input,left = of sum_n] (output_n) {};

% Lines Center Block
\draw[->] (input) -- node [name = begging] {$IN_2$} (sum);
\draw[->] (sum) -- node {} (stream);
\draw[->] (stream) -- node {} (filter);
\draw[->] (filter) -- node {} (total);
\draw[->] (total) -- node {} (delay);
\draw[->] (delay) -- node {} (segments);
\draw[->] (segments) -- node {Data} (output);

% Lines Above Center Block
\draw[->] (sum_2) -- node {} (stream_2);
\draw[->] (stream_2) -- node {} (filter_2);
\draw[->] (filter_2) -- node {} (total);

% Lines Below Center Block
\draw[->] (sum_n) -- node {} (stream_n);
\draw[->] (stream_n) -- node {} (filter_n);
\draw[->] (filter_n) -- node {} (total);

% Input Lines
\draw[->] (output_2) -- node {$IN_1$} (sum_2);
\draw[->] (output_n) -- node {$IN_n$} (sum_n);

\end{tikzpicture} }% End of makebox
\caption{New Tikz}
\label{fig:tikz }
\end{center}
\end{figure}
\end{document}

enter image description here

The idea is to first draw all the blocks and then to use the calc library (which you already loaded) to place the bullets exactly halfway between the second and third layers (this can be done with a single loop):

% Bullets
\foreach \Nodo in {sum,stream,filter}
{
  \node[rotate=90,font=\footnotesize] (dot) 
    at ( $ (\Nodo)!0.5!(\Nodo_n) $ ) {$\bullet\bullet\bullet$};
}
2
  • I thought that there would be a solution to reduce the lines of rewriting something over and over. I am impressed by those small things, loops, new commands etc. Is there a source that I could read more about it, or is it based on experience? Thank you for your time and effort to assist me on my query.
    – Thanos
    Mar 19, 2014 at 23:12
  • @Thanos You're welcome. The official source (for PGF/TikZ) is the pgf manual (but it has become over the years a "little moster" of 1100+ pages). However, you can read the introductory examples and the specific parts that you need. Mar 19, 2014 at 23:23
2

Just use a size less than 1em. Below I used 0.7em:

enter image description here

Notes:

  • For vertical spacing one should use the ex dimension instead of em (which should be used for horizontal distance.

Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc} % braces {}
\usetikzlibrary{shapes,arrows,positioning}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}

\tikzset{
 block/.style={
  draw, 
  rectangle, 
  minimum height=2em, 
  minimum width=5em,
 },
 sum/.style={
  draw, 
  circle, 
  minimum size=2em
 },
 input/.style={coordinate}, 
 output/.style={coordinate},
 mytext/.style={
  draw,
  text depth=4pt,
  text height=10pt
 }
}

\begin{figure}[!ht]
\begin{center}
\makebox[\textwidth][c]{%
\begin{tikzpicture}[auto,>=latex']

% Blocks
\node[input, name = input] {};
\node[sum, right = of input, node distance = 1em] (sum) {MP};
\node[block, right of = sum, node distance = 6.5em] (stream) {Stream $2$};
\node[sum, right = of stream, node distance = 1em] (filter) {$F_2$};
\node[sum, above = of sum, node distance = 5em] (sum_2) {MP};
\node[block, right of = sum_2, node distance = 6.5em] (stream_2) {Stream$1$};
\node[sum, right = of stream_2, node distance = 1em] (filter_2) {$F_1$};

% Bullets
\node[below of = sum, node distance = 3em] (dot) {$\bullet$} -- (dot);
\node[below of = dot, node distance = 0.7em] (dot_2) {$\bullet$} -- (dot_2);
\node[below of = dot_2, node distance = 0.7em] (dot_3) {$\bullet$} -- (dot_3);
\node[below of = stream, node distance = 3em] (dot_4) {$\bullet$} -- (dot_4);
\node[below of = dot_4, node distance = 0.7em] (dot_5) {$\bullet$} -- (dot_5);
\node[below of = dot_5, node distance = 0.7em] (dot_6) {$\bullet$} -- (dot_6);
\node[below of = filter, node distance = 3em] (dot_7) {$\bullet$} -- (dot_7);
\node[below of = dot_7, node distance = 0.7em] (dot_8) {$\bullet$} -- (dot_8);
\node[below of = dot_8, node distance = 0.7em] (dot_9) {$\bullet$} -- (dot_9);

% Blocks
\node[input, name = input_n] {};
\node[sum, below = of dot_3, node distance = 1em] (sum_n) {MP};
\node[block, right of = sum_n, node distance = 6.5em] (stream_n) {Stream $n$};
\node[sum, right = of stream_n, node distance = 1em] (filter_n) {$F_n$};

% Sum
\node[sum, right = of filter, node distance = 3em] (total) {$\sum$};

% Oneway delay
\node[block, right of = total, node distance = 7.5em] (delay) {One Way Delay};
\node[block, right of = delay, node distance = 15em] (segments) {$MP_1$ $|$ $Payload_1$ $\dots$ $MP_n$ $|$ $Payload_n$};
\node[output,right = of segments] (output) {};

% Inputs
\node[input,left = of sum_2] (output_2) {};
\node[input,left = of sum_n] (output_n) {};

% Lines Center Block
\draw[->] (input) -- node [name = begging] {$IN_2$} (sum);
\draw[->] (sum) -- node {} (stream);
\draw[->] (stream) -- node {} (filter);
\draw[->] (filter) -- node {} (total);
\draw[->] (total) -- node {} (delay);
\draw[->] (delay) -- node {} (segments);
\draw[->] (segments) -- node {Data} (output);

% Lines Above Center Block
\draw[->] (sum_2) -- node {} (stream_2);
\draw[->] (stream_2) -- node {} (filter_2);
\draw[->] (filter_2) -- node {} (total);

% Lines Below Center Block
\draw[->] (sum_n) -- node {} (stream_n);
\draw[->] (stream_n) -- node {} (filter_n);
\draw[->] (filter_n) -- node {} (total);

% Input Lines
\draw[->] (output_2) -- node {$IN_1$} (sum_2);
\draw[->] (output_n) -- node {$IN_n$} (sum_n);

\end{tikzpicture} }% End of makebox
\caption{New Tikz}
\label{fig:tikz }
\end{center}
\end{figure}
\end{document}
1
  • So simple I did not even think about it. Thank you for your time and effort. I appreciate the assistance.
    – Thanos
    Mar 19, 2014 at 23:09

You must log in to answer this question.

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