如何在 tikz 中创建平行的文本列?

如何在 tikz 中创建平行的文本列?

我正在尝试在 tikz 中重新创建此图像: 在此处输入图片描述

我已经设法绘制了基本结构。我不知道该如何搜索这个问题,但无法处理这两个“列”文本,即“捕获文件”和“CSV 文件”部分。此外,与我使用的方法相比,有没有更好的方法来处理最右边和最左边的那些文本框(“帧长度 IP 长度...”和“每秒数据包数”)?

    \documentclass{article}    
    \usepackage{lipsum}
    \usepackage{tikz}
    \usetikzlibrary{positioning}
    \usetikzlibrary{arrows}
    
    \begin{document}
    
    \begin{figure}
        \centering
        \begin{tikzpicture}
        \tikzstyle{arrow} = [thick,->,>=stealth]
    
        \node (block1a) [rectangle] {Capture File};
        \node (block1b) [rectangle, right= of block1a] {CSV File};
    
        \node (block2a) [rectangle, below=0.7cm of block1a, align=center, minimum width=3cm] {Feature Extraction  \\ Algorithm};
    
        \node (sidetext1) [rectangle, align= left, left= of block2a] {Frame length \\ IP length \\ TCP length \\ UDP length \\ Inter-packet delay};
    
        \draw[arrow] (block2a) -- (sidetext1);
    
        \node (block2b) [rectangle, below=0.7cm of block1b, align=center] {PPS Algorithm};
    
        \node(sidetext2)[rectangle, align= left, right= of block2b] {Packets per Second};
    
        \draw[arrow] (block2b)--(sidetext2);
    
        \node (block3a) [rectangle,below=0.7cm of block2a, align=center] {mean \& \\ standard deviation};
    
        \node (block3b) [rectangle,below=0.7cm of block2b,align=center] {mean \& \\ standard deviation};
        
        \node (final) [rectangle, minimum width=8cm, minimum height=0.8cm, text centered, draw=black, below=1 cm of block3a] {Feature Set};
    
        \draw[arrow] (block1a.south) -- (block2a.north);      
        \draw[arrow] (block2a.south)--(block3a.north);
        \draw[arrow] (block3a.south)--(final.north);
        \draw[arrow] (block1b.south)--(block2b.north);
        \draw[arrow] (block2b.south) --(block3b.north);
        \draw[arrow] (block3b.south) -- (final);
        
        \end{tikzpicture}
    \end{figure} 
\end{document}

答案1

改编

  • 使用\tikzset而不是\tikzstyle(见应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式?
  • 删除多余的rectangle选项(因为它是默认选项)
  • 重新排列代码
  • 将节点放置block3b在 处(block2b|-block3a),使其水平和垂直对齐
  • 添加\usetikzlibrary{calc}节点final到两列中间([yshift=-10mm] $(block3a.south)!.5!(block3b.south)$)
  • 绘制垂直final箭头(block3a.south|-final.north)
  • 删除了前后的空格\\
  • sidenode减小了侧节点的字体大小并为其设置了样式
  • 将侧节点的线条样式更改为dashed与其他箭头区分开来

结果

在此处输入图片描述

代码

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}

\begin{document}

\begin{figure}
    \centering
    \begin{tikzpicture}[
        arrow/.style = {thick,->,>=stealth},
        sidenode/.style = {font=\footnotesize, align=left},
    ]
        
        \node (block1a) [] {Capture File};
        \node (block2a) [below=7mm of block1a, align=center, minimum width=3cm] {Feature Extraction\\Algorithm};
        \node (block3a) [below=7mm of block2a, align=center] {mean \&\\standard deviation};
        
        \node (block1b) [right=20mm of block1a] {CSV File};
        \node (block2b) [below=of block1b, align=center] {PPS Algorithm};
        \node (block3b) [align=center] at (block2b|-block3a) {mean \&\\standard deviation};
        
        \node (sidetext1) [sidenode, left=of block2a] {Frame length\\IP length\\TCP length\\UDP length\\Inter-packet delay};
        \node (sidetext2) [sidenode, right=of block2b] {Packets per Second};
        
        \node (final) [minimum width=8cm, minimum height=0.8cm, text centered, draw=black] at ([yshift=-10mm] $(block3a.south)!.5!(block3b.south)$) {Feature Set};
        
        \draw[dashed] (block2a) -- (sidetext1);
        \draw[dashed] (block2b) -- (sidetext2);
        
        \draw[arrow] (block1a.south) -- (block2a.north);      
        \draw[arrow] (block2a.south) -- (block3a.north);
        \draw[arrow] (block3a.south) -- (block3a.south|-final.north);
        \draw[arrow] (block1b.south) -- (block2b.north);
        \draw[arrow] (block2b.south) -- (block3b.north);
        \draw[arrow] (block3b.south) -- (block3b.south|-final.north);
    \end{tikzpicture}
\end{figure}

\end{document}

相关内容