流程图中箭头的自定义位置

流程图中箭头的自定义位置

这是我的代码:

\documentclass[12pt,twoside,a4paper]{book}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{decument}
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm,
text centered, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm,
text centered, draw=black, fill=green!30]
\tikzstyle{startstop} = [draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110,
minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm,
text centered, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm,
text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]


\begin{tikzpicture}[node distance=2cm]
\node (pro1)[process, below of=in1]{Process 1};
\node (dec1) [decision, below of=pro1, yshift=-0.5cm] {Decision 1};
\node (pro2b) [process, right of=dec1, xshift=2cm] {Process 2b};
\draw [arrow] (in1) -- (pro1);
\draw [arrow] (pro1) -- (dec1);
\draw [arrow] (dec1) -- (pro2a);
\draw [arrow] (dec1) -- (pro2b);
\draw [arrow] (dec1) -- node[anchor=east] {yes} (pro2a);
\draw [arrow] (dec1) -- node[anchor=south] {no} (pro2b);
\draw [arrow] (pro2b) |- (pro1);
\end{tikzpicture}
\end{document}

得出的结果为: 在此处输入图片描述

但我希望:

在此处输入图片描述

我怎样才能绘制这个图?

答案1

pro1您可以在箭头的中点放置一个辅助坐标dec1

\draw [arrow] (pro1) -- coordinate[midway] (aux) (dec1);

然后使用该坐标绘制箭头:

\draw [arrow] (pro2b) |- (aux);

在此处输入图片描述

完整代码:

\documentclass[12pt,twoside,a4paper]{book}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}

\begin{document}
\tikzset{
  process/.style={rectangle, minimum width=3cm, minimum height=1cm,
text centered, draw=black, fill=orange!30},
decision/.style={diamond, minimum width=3cm, minimum height=1cm,
text centered, draw=black, fill=green!30},
startstop/.style={draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em},
io/.style={trapezium, trapezium left angle=70, trapezium right angle=110,
minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30},
process/.style={rectangle, minimum width=3cm, minimum height=1cm,
text centered, draw=black, fill=orange!30},
decision/.style={diamond, minimum width=3cm, minimum height=1cm,
text centered, draw=black, fill=green!30},
arrow/.style={thick,->,>=stealth}
}

\begin{tikzpicture}
\coordinate (in1) {};
\node (pro1)[process, below = of in1]{Process 1};
\node (dec1) [decision, below = of pro1, yshift=-0.5cm] {Decision 1};
\node (pro2b) [process, right = of dec1] {Process 2b};

\draw [arrow] (in1) -- (pro1);
\draw [arrow] (pro1) -- coordinate[midway] (aux) (dec1);
%\draw [arrow] (dec1) -- (pro2a);
\draw [arrow] (dec1) -- (pro2b);
%\draw [arrow] (dec1) -- node[anchor=east] {yes} (pro2a);
\draw [arrow] (dec1) -- node[anchor=south] {no} (pro2b);
\draw [arrow] (pro2b) |- (aux);
\end{tikzpicture}
\end{document}

评论

  • 我修改了原来的代码。我使用了更方便的\tikzset语法,而不是旧的\tikzstyle

  • 我还添加了缺失的坐标并注释掉了由于某些节点未定义而产生错误的部分代码。

  • 我在库的帮助下将旧的of=语法改为更方便节点定位的语法。=ofpositioning

答案2

\tikzstyle您可以在流程 1 和决策 1 之间的箭头中间放置一个坐标,如下所示。您还应该将已弃用的的用法更改为 ,并使用库 ie\tikzset提供的新语法,而不是。最后,替换。positioningbelow=of ...below of=...arrows.metaarrows

\documentclass[tikz, border=5pt]{standalone}

\usetikzlibrary{shapes,arrows.meta,positioning}

\begin{document}
\tikzset{
    process/.style = {rectangle, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=orange!30},
    decision/.style = {diamond, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=green!30},
    startstop/.style = {draw, ellipse,fill=red!20, node distance=3cm,minimum height=2em},
    io/.style = {trapezium, trapezium left angle=70, trapezium right angle=110,minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30},
    process/.style = {rectangle, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=orange!30},
    decision/.style = {diamond, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=green!30},
    arrow/.style = {thick,->,>=stealth},
}


\begin{tikzpicture}[node distance=2cm]
\coordinate (in1);
\node (pro1)[process, below=of in1]{Process 1};
\node (dec1) [decision, below=of pro1, yshift=-0.5cm] {Decision 1};
\coordinate [below=of dec1] (pro2a);
\node (pro2b) [process, right=of dec1, xshift=2cm] {Process 2b};
\draw [arrow] (in1) -- (pro1);
\draw [arrow] (pro1) -- (dec1) coordinate [midway] (mid1);
\draw [arrow] (dec1) -- (pro2a);
\draw [arrow] (dec1) -- (pro2b);
\draw [arrow] (dec1) -- node[anchor=east] {yes} (pro2a);
\draw [arrow] (dec1) -- node[anchor=south] {no} (pro2b);
\draw [arrow] (pro2b) |- (mid1);
\end{tikzpicture}
\end{document}

中途的箭头

答案3

PSTricks 解决方案:

\documentclass{article}

\usepackage{pstricks}

\begin{document}

\psset{fillstyle = solid, arrows = ->}
\begin{pspicture}(7.5,7.5)
  \psline(1.5,7.5)(1.5,6.5)
  \psframe[fillcolor = orange!40](0,5)(3,6.5)
  \rput(1.5,5.75){Process~1}
  \psline(1.5,5)(1.5,4)
  \pspolygon[fillcolor = green!40](0,2.5)(1.5,4)(3,2.5)(1.5,1)
  \rput(1.5,2.5){Decision~1}
  \psline(1.5,1)(1.5,0)
  \rput(1.15,0.5){yes}
  \psline(3,2.5)(4.5,2.5)
  \rput(3.75,2.7){no}
  \psframe[fillcolor = orange!40](4.5,1.75)(7.5,3.25)
  \rput(6,2.5){Process~2b}
  \psline(6,3.25)(6,4.5)(1.5,4.5)
\end{pspicture}

\end{document}

输出

相关内容