如何使用 TikZ 在流程图中绘制箭头?

如何使用 TikZ 在流程图中绘制箭头?

我正在尝试重现此流程图,但箭头有问题。有什么解决办法吗?

在此处输入图片描述

我的尝试。

\begin{tikzpicture}[
    node distance = 1.5cm and 2mm,
   process/.style = {rectangle, minimum width=6cm, minimum height=2cm, align=center, fill=gray!10}]
\node [process] (a)      {Specification and estimation of VAR model}; % A-1
\node [process, below=of a] (b)        {Model checking};
\node [process, below=of b] (c)        {Forecasting};
\node [process, below right=of b] (d)   {Structural analysis}; % A-6
%%
\draw[arrows=-{Stealth[scale=1.2]}, rounded corners, thick]
  (a) -- (b) 
  (b) -| +(2,4) -| +(2,1) -| node {d} (a)
  (b) edge (c)
  (b) edge (d);
  
\end{tikzpicture}
\caption{Workflow of VAR Analysis.}
\label{fig:var-workflow}
\end{figure}

答案1

为了练习,由于您的流程图留在树上,我将使用forest以下包来绘制它forked edge

在此处输入图片描述

\documentclass[border=3.141592mm]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{forest}
for tree = {
% nodes
    draw, 
    minimum width=22mm, minimum height=12mm, 
    align = center, 
   anchor = north,
% tree  
     grow = south,
forked edge,    
    edge = {-Stealth, semithick},     
    s sep = 2mm,     
    l sep = 8mm,     
 fork sep = 4mm,     
            } 
[Specification and estimation\\ of VAR model, name=a
    [Model checking, name=b
        [Forecasting]
        [Structural\\ analysis]
    ] 
]
%%
\draw[-Stealth, semithick] (b.east) -- ++(1.5,0) |- (a);
    \end{forest}
\end{document}

答案2

假设您在图表末尾做了您想做的事情,下面是处理右箭头的方法。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta}

\begin{document}
    \begin{tikzpicture}[
    node distance = 1.5cm and 2mm,
   process/.style = {rectangle, minimum width=6cm, minimum height=2cm, align=center, fill=gray!10}]
\node [process] (a)      {Specification and estimation of VAR model}; % A-1
\node [process, below=of a] (b)        {Model checking};
\node [process, below=of b] (c)        {Forecasting};
\node [process, below right=of b] (d)   {Structural analysis}; % A-6
%%
\draw[arrows=-{Stealth[scale=1.2]}, rounded corners, thick]
  (a) -- (b) 
  (b.east) -| ++(1.5,1) |- (a)
  (b) edge (c)
  (b) edge (d);
  
\end{tikzpicture}
\end{document}

带箭头的图表

答案3

另一个简短的解决方案是使用pstricksstackengine,使用一个简单的tabular

\documentclass[svgnames]{article}
\usepackage{array, booktabs}
\usepackage[usestackEOL]{stackengine}
\usepackage{pst-node}%
\newcommand{\chartnode}[2]{\psDefBoxNodes{#1}{\fbox{\quad\Shortunderstack[l]{#2}\quad}}}

\begin{document}

\begin{tabular}{c!{\quad}c}
  \multicolumn{2}{c}{\chartnode{V}{Specification and \\ estimation of VAR model}}\\
\addlinespace[6ex]
 \multicolumn{2}{c}{\chartnode{M}{Model checking}}\\
\addlinespace[10ex]
  \chartnode{F}{Forecasting}& \chartnode{S}{Structural\\ analysis}
%%% arrows
\psset{arrows=->, arrowinset=0.1, linejoin=1, linearc=0.05}
\ncline{V:bC}{M:tC}
\ncbar{M:Cr}{V:Cr}\nbput{\Centerstack[l]{model\\rejected}}
\psset{angleA=-90, angleB=90}
\ncangle{M:bC}{F:tC}\ncangle{M:bC}{S:tC}\naput[npos=0.4]{model accepted}
\end{tabular}

\end{document}

在此处输入图片描述

答案4

我没有修改我之前的答案,因为我有一个非常不同的选择。
在和之间是一个简单的图表,这里是节点forest的使用,其中和。childsibling distancelevel distance

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta}

\begin{document}
    \begin{tikzpicture}[
        level 1/.style={level distance=3cm},
        level 2/.style={level distance=4cm},
        sibling distance=5cm,
        edge from parent/.style={draw=none},
        process/.style = {
            rectangle,
            minimum width=3.5cm,
            minimum height=2cm,
            align=center,
            fill=gray!10,
            inner sep=10pt,
            rounded corners=10pt}]
   
   
        \node [process] (a) {Specification and estimation of VAR model} % A-1
            child  {node[process] (b)        {Model checking}
            child  {node[process] (c)  {Forecasting}}
            child  {node[process] (d) {Structural analysis}}}; % A-6
        
        \begin{scope}[arrows=-{Stealth[scale=1.2]}, rounded corners, thick]
            \draw (a) -- (b); 
            \draw (b.east) -| ++(2.5,1) |- (a) node[text width=1.5cm, align=center,pos=0.2,right] {model rejected};
            \draw (b.south) |-++ (0,-1) node[pos=0.25,right=5pt] {model accepted} -| (c) ;
            \draw (b.south) |-++ (0,-1) -| (d)  ;       
        \end{scope}

  
\end{tikzpicture}
\end{document}

完整图表

相关内容