块与项目符号间距相结合

块与项目符号间距相结合

我一直在尝试创建我的第二个 Tikz 模型TikZ:感知器图。我设法根据我的初学者知识和实验对其进行了修改,但我遗漏了部分,我无法弄清楚如何制作子弹。我试图缩小距离,但没有效果。我尝试过distance node = 1 em但目前没有成功。有没有可能解决我的问题?提供了输出示例。输出任何建议都值得赞赏。

\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}

答案1

我建议您采用不同的方法来保持各层之间的一致间距:

\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}

在此处输入图片描述

这个想法是首先绘制所有块,然后使用calc库(您已经加载)将子弹准确地放置在第二层和第三层之间的中间(这可以通过单个循环完成):

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

答案2

只需使用小于 的尺寸即可1em。下面我使用了0.7em

在此处输入图片描述

笔记:

  • 对于垂直间距,应该使用ex尺寸而不是em(应该用于水平距离。

代码:

\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}

相关内容