tikz 流程图中箭头的位置

tikz 流程图中箭头的位置

我有以下 tickz 流程图,但我希望从“计算颜色特征”节点出发的箭头停在“SVM 和 RF 模型”节点的右上角。我该怎么做?

在此处输入图片描述

这是我的代码。

\documentclass{article}
\usepackage{tikz}


\begin{figure}[! h]
\begin{center}
\begin{tikzpicture}

\tikzstyle{block1} = [rectangle, draw,fill=gray!20, 
    text width=3cm, text centered, rounded corners, minimum height=1cm]
\tikzstyle{block2} = [rectangle, draw,fill=gray!20, 
    text width = 2cm, text centered, rounded corners, minimum height = 2cm]

  
   \node[block1](Input){Input images};
   
  
   \node[block2, below of = Input , xshift = -2cm , yshift = -2cm](glcm){Compute GLCM matrix};
   
   \node[block2, below of = Input , xshift = 2cm , yshift = -2cm](col_features){Compute colour features};
   
  \node[block1, below of = glcm , yshift = -1cm](ext_features){Calculate extracted features};
   
   
   \node[block1, below of = ext_features , yshift = -1cm](average_feature){Calculate average of features};
   
  
  \node[block1, below of = average_feature , yshift = -1cm](models){SVM and RF models};
    
   \node[block2, below of = models , xshift = -2cm , yshift = -2cm](tumor){Image contains a tumor};
   
   \node[block2, below of = models , xshift = 2cm , yshift = -2cm](no_tumor){Image does not contain tumor};

 

    \draw[->](Input)--(glcm);
    \draw[->](glcm)--(ext_features);
    \draw[->](ext_features)--(average_feature);
    \draw[->](average_feature)--(models);
    \draw[->](models)--(tumor);
    \draw[->](models)--(no_tumor);
    \draw[->](Input)--(col_features);
    \draw[->](col_features)--(models);

\end{tikzpicture}
\end{center}
\caption{Feature extraction flow chart}
\label{fig:feat_ext}
\end{figure}
\end{document}```

答案1

欢迎来到 TeX.SX!您可以使用锚点。TiZ 为默认节点形状提供了一组此类锚点,您可以通过将锚点名称添加到节点名称(用点/句号连接)来引用这些锚点。大多数节点形状都提供锚点northsoutheast及其west组合,例如north east,这是您可以在此处使用的锚点。

参见第 71 章Z/PGF 手册其中shapes讨论了哪些锚点可用于预定义的节点形状的库。

\documentclass[tikz, border=1mm]{standalone}

\begin{document}
\begin{tikzpicture}

    \tikzstyle{block1} = [rectangle, draw,fill=gray!20, 
    text width=3cm, text centered, rounded corners, minimum height=1cm]
    \tikzstyle{block2} = [rectangle, draw,fill=gray!20, 
    text width = 2cm, text centered, rounded corners, minimum height = 2cm]
    
    \node[block1](Input){Input images};
    \node[block2, below of = Input, xshift = -2cm, yshift = -2cm](glcm){Compute GLCM matrix};
    \node[block2, below of = Input, xshift = 2cm, yshift = -2cm](col_features){Compute colour features};
    \node[block1, below of = glcm, yshift = -1cm](ext_features){Calculate extracted features};
    \node[block1, below of = ext_features, yshift = -1cm](average_feature){Calculate average of features};
    \node[block1, below of = average_feature, yshift = -1cm](models){SVM and RF models};
    \node[block2, below of = models, xshift = -2cm, yshift = -2cm](tumor){Image contains a tumor};
    \node[block2, below of = models, xshift = 2cm, yshift = -2cm](no_tumor){Image does not contain tumor};

    \draw[->](Input)--(glcm);
    \draw[->](glcm)--(ext_features);
    \draw[->](ext_features)--(average_feature);
    \draw[->](average_feature)--(models);
    \draw[->](models)--(tumor);
    \draw[->](models)--(no_tumor);
    \draw[->](Input)--(col_features);
    \draw[->](col_features)--(models.north east);

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

我不会使用\tikzstylenor below of,但会使用库below=of中的positioning。但是,对于这样的树形图,有一个更强大的选项:forest,所以你甚至不必担心这样的事情。此外,在这种情况下,弯曲的箭头可能看起来更好。

\documentclass{article}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
 for tree={rectangle, draw,fill=gray!20, 
    text width=3cm,text centered, rounded corners, minimum height=1cm,
    edge={->}}
   [Input images
    [Compute\\ GLCM\\ matrix
     [Calculate extracted features
      [Calculate average of features
       [SVM and RF models,alias=BR
        [Image\\ contains\\ a tumor]
        [Image\\ does not\\ contain tumor]
       ]    
      ] 
     ]  
    ] 
   [Compute\\ colour\\ features,alias=TR]
  ] 
 \draw[->] (TR) to[out=-90,in=45] (BR.north east); 
\end{forest}  
\end{document}

在此处输入图片描述

相关内容