流程图中的箭头有问题

流程图中的箭头有问题

我在尝试重新绘制从一个节点到另一个节点的箭头时遇到了困难。

平均能量损失

\documentclass[a4paper, 11pt]{report}
\usepackage[toc,page]{appendix}
\usepackage{pgfgantt}
\usepackage{geometry}

\geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }

\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, shadows}
\usetikzlibrary{fit,backgrounds}
\usetikzlibrary{shadows.blur}
\begin{document}

\begin{center}
\tikzset{
    decision/.style={
        diamond, draw, fill=blue!20, text width=4.5em, text badly centered, 
        node distance=3cm, inner sep=0pt, drop shadow
    },
    block/.style={
        rectangle, draw, fill=blue!20, text width=7em, text centered, rounded corners, 
        minimum height=2em, drop shadow
    },
    line/.style={
        draw, -latex'
    },
    cloud/.style={
        draw, ellipse,fill=red!20, node distance=3cm, minimum height=2em, drop shadow
    },
    rect/.style={
        rectangle, rounded corners, minimum width=3.5cm, minimum height=1cm,
        text centered, draw=black, fill=blue!10,blur shadow
    },
    arrow/.style={
        thick,->,>=stealth
    }
}
    \begin{tikzpicture}[node distance = 2cm, auto]
        % Place nodes

    \node [cloud] (start) {Start};
    \node [decision, below of=start] (newuser) {New User?};
    \node [decision, below left=3cm of newuser] (christmassale) {Christams Sale?};
    \node [decision, below right=3cm of newuser] (newcustomerthruref) {New Customer through Reference};
    \node [decision, below left=2cm of christmassale] (firstorder)  {First Order?};     
    \node [block, below left=1cm of firstorder] (discount15) {Total Discount +15\%};
    \node [decision, below right=2cm and 1cm of discount15] (coupon) {Coupon?};  
    


    \path [line] (start) -- (newuser);
    \path [line] (newuser) -| (christmassale);
    \path [line] (christmassale) -| (firstorder);
    \path [line] (firstorder) -| (discount15);
    \path [line] (discount15) |- (coupon);
    \path [line] (discount15) |- (coupon);
    \path [line] (christmassale) |- (coupon);
    \path [line] (firstorder) -| (coupon);
    
  % \draw [arrow] (discount15.east) |- ++(1.5cm,1.5cm) node[red] {$\bullet$} -| ([xshift=1cm]coupon.south);

    
\end{tikzpicture}
\end{center}
\end{document}

电流输出

在此处输入图片描述

理想输出

2个问题:

  • 如何更改路径/箭头的垂直长度(以红色表示)以使它们都统一?
  • 我如何绘制指向 [圣诞节促销] >> [优惠券] && [首单] >> [优惠券] 的箭头,如下所示? 在此处输入图片描述

我尝试过

我尝试使用以下代码,但无济于事

\draw [arrow] (discount15.east) |- ++(1.5cm,1.5cm) node[red] {$\bullet$} -| ([xshift=1cm]coupon.south);

答案1

您的图表中发生了许多不同的事情,很难追踪:

连接的垂直部分的长度与节点的垂直距离及其垂直尺寸直接相关。

为了解决这个问题,我们需要将节点放置得更自动化一些,因为node distanceand带的乘以 2 的平方根并放置在对角线罗盘锚点之间。即使给出两个节点距离,垂直and水平也会对diamond形状产生意想不到的结果。


在寒冷中我定义风格

  • below and left = of <ref>
  • below and right = of <ref>

其作用类似于below = of <ref>.center将新节点的北锚点相对于引用节点的中心锚点放置。这就是连接的垂直长度!

此外,节点会向左或向右移动大约水平节点距离的量。为此,我使用了ext.positioning-plus提供 PGFMath 函数的库,x_node_dist这样您只需提供节点距离一次


为了连接节点,我将使用edge语法,因为它可以更容易地为多个连接应用通用样式。

提供ext.paths.ortho

  • 路径操作|-|
  • ortho/install shortcuts安装-||-|作为to paths。

此外,从目标节点(的边界)取负数以确保与最后一个节点有一条公共线。在这里,我通过库ortho/distance使用了引用。y_node_distext.positioning-plus

rdldr好的,d自己的,伊夫特,dchristmassale最复杂的连接(自身)样式在边缘起始节点右侧但高度相同处找到一个点,以确保最复杂的连接重叠。它还使用确保此连接的长垂直部分与离开左侧节点的连接x_node_dist距离相同。christmassale

代码

\documentclass[tikz, 11pt,convert]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows.meta, positioning, shadows.blur}
\usetikzlibrary{ext.positioning-plus, ext.paths.ortho, quotes}
\begin{document}
\begin{tikzpicture}[
  node distance = 2cm and 3cm,
  decision/.style = {
    diamond, draw, fill=blue!20, text width=4.5em, text badly centered,
    inner sep=0pt, drop shadow},
  block/.style = {
    rectangle, draw, fill=blue!20, text width=7em, text centered,
    rounded corners, minimum height=2em, drop shadow},
  line/.style  = -Latex,
  cloud/.style = {draw, ellipse, fill=red!20, minimum height=2em, drop shadow},
  below and left/.style ={below={#1.center}, xshift=-x_node_dist},
  below and right/.style={below={#1.center}, xshift= x_node_dist},
]

\node [cloud] (start) {Start};
\node [decision, below=of start] (newuser) {New User?};
\node [decision, below and left =of newuser] (christmassale)      {Christmas Sale?};
\node [decision, below and right=of newuser] (newcustomerthruref) {New Customer through Reference};
\node [decision, below and left =of christmassale] (firstorder)   {First Order?};
\node [block,    below and left =of firstorder]    (discount15)   {Total Discount +15\%};
\node [decision, below and right=of discount15]    (coupon)       {Coupon?};

\path[
  line, near start,
  ortho/install shortcuts, % for -| and |-|
  ortho/distance=-.25*y_node_dist,
  rdld/.style={to path={
    --  ([xshift=x_node_dist] christmassale|-\tikztostart)\tikztonodes
    |-| (\tikztotarget)}}]
  (start)              edge                     (newuser)
  [-|] (newuser)       edge[      "no"']        (christmassale) 
                       edge[      "yes"]        (newcustomerthruref)
       (christmassale) edge[      "no"']        (firstorder)
                       edge[rdld, "yes" midway] (coupon)
       (firstorder)    edge[      "no"']        (discount15)
                       edge[rdld, "yes" midway] (coupon)
       (discount15)    edge[|-|]                (coupon)
;
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容