工作流程图中的相对箭头位置

工作流程图中的相对箭头位置

我正在尝试重新创建下面的图像,并对其进行了小幅修改使其垂直。

在此处输入图片描述

然而,我遇到了一些关于箭头长度的小问题,

在此处输入图片描述

有什么想法可以让箭头长度相同,并正确居中吗?是否可以让所有框的高度/宽度也相同?

\documentclass[svgnames]{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings,shapes.arrows,shadows}
\usetikzlibrary{shapes.geometric}

\usepackage{xparse}

\usepackage{lipsum}

\tikzfading[name=arrowfading, top color=transparent!0, bottom color=transparent!95]
\tikzset{arrowfill/.style={#1,general shadow={fill=black, shadow yshift=-0.8ex, path fading=arrowfading}}}
\tikzset{arrowstyle/.style n args={3}{draw=#2,arrowfill={#3}, single arrow,minimum height=#1, single arrow,
single arrow head extend=.3cm,}}

\NewDocumentCommand{\tikzfancyarrow}{O{2cm} O{FireBrick} O{top color=OrangeRed!20, bottom color=Red} m}{
\tikz[baseline=-0.5ex]\node [arrowstyle={#1}{#2}{#3}] {#4};
}

\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30]

\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]

\begin{document}

\begin{tikzpicture}[node distance=2cm]

\node (start) [startstop, align=left] {Your computer \\ \\ 3. Update \\ 4. Commit};

\node (push) [above right of=start, xshift=2cm, yshift=-1cm] {\tikzfancyarrow[2cm][FireBrick][top color=OrangeRed!20, bottom color=Red,shape border rotate=180]{2. Clone}};
\node (clone) [below right of=start, xshift=2cm, yshift=1cm] {\tikzfancyarrow{5. Push}};


\node (in1) [io, right of=clone, xshift=2cm, yshift=0.33cm, align=left] {Your GitHub-repo \\ \footnotesize github.com/you/coolproject};

\node (pull) [above right of=in1, xshift=2cm, yshift = -1cm] {\tikzfancyarrow[2cm][FireBrick][top color=OrangeRed!20, bottom color=Red,shape border rotate=180]{1. Fork}};
\node (fork) [below right of=in1, xshift=2cm, yshift = 1cm] {\tikzfancyarrow{6. Pull request}};

\node (pro1) [process, right of=fork, xshift=2cm, align=left, yshift=0.33cm] {Joe's GitHub-repo \\ \footnotesize github.com/joe/coolproject};

\end{tikzpicture}
\end{document}

答案1

作为起点(因为我迷失在你的代码中:-():

编辑: 再次阅读您的问题后,我意识到您希望所有箭头形状的长度相等,所有块的高度相等(我说得对吗?)。这可以通过text width为箭头规定尺寸并将minimum height其他节点的尺寸放大来获得。更正后的代码:

\documentclass[svgnames, margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, shadows, shapes.arrows, shapes.geometric}

\tikzset{
   arrowstyle/.style n args = {3}{single arrow, single arrow head extend=3mm,
                        minimum width=12mm, text width=24mm,
                        draw=#1, top color=#2, bottom color=#3,
                        drop shadow={shadow xshift=0ex, shadow yshift=-0.8ex},
                        anchor=west
                                 },
 arrowstyle/.default = {red}{OrangeRed!20}{Red},
    startstop/.style = {rectangle, rounded corners, draw=black, fill=red!30,
                        minimum width=33mm, minimum height=22mm, align=left},
           io/.style = {trapezium,
                        trapezium left angle=70, trapezium right angle=110,
                        trapezium stretches body,
                        draw=black, fill=blue!30,
                        minimum width=33mm, minimum height=22mm, align=left},
      process/.style = {rectangle, draw=black, fill=orange!30,
                        minimum width=33mm, minimum height=22mm, align=left},
        }

\begin{document}
    \begin{tikzpicture}[
node distance = 6mm and 9mm]
\node (start)   [startstop]                             {Your computer\\ \\ 3. Update \\ 4. Commit};
\node (push)    [above right=of start.east,
                 arrowstyle, shape border rotate=180]   {2. Clone};
\node (clone)   [below right=of start.east,
                 arrowstyle]                            {5. Push};
%
\node (in1)     [io, right=of clone.east |- start]      {Your GitHub-repo \\
                                            \footnotesize github.com/you/coolproject};
\node (pull)    [above right=of in1.east,
                 arrowstyle, shape border rotate=180]   {1. Fork};
\node (fork)    [below right=of in1.east,
                 arrowstyle]                            {6. Pull request};
%
\node (pro1)    [process, right=of fork.east |- start]  {Joe's GitHub-repo \\
                                \footnotesize github.com/joe/coolproject};
\end{tikzpicture}
\end{document}
  • 在我的代码中删除所有嵌套的tikz图片,重新设计节点样式并统一它们的定义方式(仅使用tikzset),使用tikzpositioning进行节点定位
  • 观察节点处选项的新序列arrowstyle:首先是定位,然后是节点样式。这是必要的,以确保节点锚点不会被定位覆盖

在此处输入图片描述

  • 如果您想复制所显示的图像,将上述代码重新排列一下相对简单:

    \documentclass[svgnames, margin=3mm]{standalone}
    \usepackage{tikz}
    \usetikzlibrary{positioning, shadows, shapes.arrows, shapes.geometric}
    
    \tikzset{
       arrowstyle/.style n args = {3}{single arrow, single arrow head extend=3mm,
                            minimum width=12mm, text width=24mm, align=center,
                            draw=#1, top color=#2, bottom color=#3,
                            drop shadow={shadow xshift=0ex, shadow yshift=-0.8ex},
                            anchor=west
                                     },
       arrowstyle/.default = {red}{OrangeRed!20}{Red},
        startstop/.style = {rectangle, rounded corners, draw=black, fill=red!30,
                            minimum width=33mm, minimum height=22mm, align=left},
               io/.style = {trapezium,
                            trapezium left angle=70, trapezium right angle=110,
                            trapezium stretches body,
                            draw=black, fill=blue!30,
                            minimum width=33mm, minimum height=22mm, align=left},
          process/.style = {rectangle, draw=black, fill=orange!30,
                            minimum width=33mm, minimum height=22mm, align=left},
            }
    
    \begin{document}
    
        \begin{tikzpicture}[
    node distance = 6mm and 9mm]
    \node (in1)     [io]                                    {Your GitHub-repo \\
                                               \footnotesize github.com/you/coolproject};
    %
    \node (pull)    [above right=of in1.east,
                     arrowstyle, shape border rotate=180]   {1. Fork};
    \node (fork)    [below right=of in1.east,
                     arrowstyle]                            {6. Pull request};
    \node (pro1)    [process, right=of fork.east |- in1]    {Joe's GitHub-repo \\
                                               \footnotesize github.com/joe/coolproject};
    %
    \node (clone)   [below  left=of in1.south,
                     arrowstyle,rotate=90,anchor=east]                {5. Push};
    \node (push)    [below right=of in1.south,
                     arrowstyle, rotate=270,anchor=west]                 {2. Clone};
    \node (start)   [startstop,
                     below=of in1 |- clone.west]      {Your computer\\ \\ 3. Update \\ 4. Commit};
    \end{tikzpicture}
    
    \end{document}
    

在此处输入图片描述

答案2

如果我理解正确的话,你的问题是控制箭头的长度和方向。这两件事都可以用以下方法解决Torbjørn T. 的回答很棒,我针对当前任务对其进行了修改。您应该能够使用简单的 edge 命令完成所有这些操作

\path
([xshift=7mm]in1.south) edge[fancy arrow={}{5.~Push}] 
([xshift=7mm]start.north);

其中坐标指的是起点和终点(我移动了它们,因为你想要箭头指向相反的方向),第一个参数是一个选项,在大多数情况下你可能不需要它,第二个参数是箭头内的文本。

在此处输入图片描述

\documentclass[svgnames]{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings,shapes.arrows,shadows,positioning,calc}
\usetikzlibrary{shapes.geometric}

\usepackage{xparse}

\usepackage{lipsum}

\tikzfading[name=arrowfading, top color=transparent!0, bottom color=transparent!95]
\tikzset{arrowfill/.style={#1,general shadow={fill=black, shadow yshift=-0.8ex, path fading=arrowfading}}}
\tikzset{arrowstyle/.style n args={3}{draw=#2,arrowfill={#3}, single arrow,minimum height=#1, single arrow,
single arrow head extend=.3cm,}}

\tikzset{fancy arrow/.style 2 args=%
{to path={let \p1 = ($(\tikztotarget)-(\tikztostart)$),
            \p2=($(\tikztotarget)!0.5!(\tikztostart)$),
            \n1 = {int(mod(scalar(atan2(\y1,\x1))+360, 360))}, % calculate angle in range [0,360)
            \n2 = {veclen(\x1,\y1)}
        in
         (\p2)
        node[draw,arrowstyle={1pt}{FireBrick}{top color=OrangeRed!20, bottom color=Red},
             minimum height=\n2-\pgflinewidth-5pt,
             single arrow,text=black,inner sep=1pt,
             rotate=\n1, % not shape border rotate, because that for some reason didn't work
             anchor=mid, % anchor=tip added, pos=0.5 removed
             #1
             ]{#2}
         }}}

\tikzset{startstop/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30},
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},
}

\begin{document}

\begin{tikzpicture}

\node (start) [startstop, align=left] {Your computer \\ \\ 3. Update \\ 4. Commit};

\node (in1) [io, above=3cm of start, align=left] {Your GitHub-repo \\ \footnotesize github.com/you/coolproject};

\node (pro1) [process, right=3cm of in1,align=left] {Joe's GitHub-repo \\ \footnotesize github.com/joe/coolproject};
\path ([yshift=4mm]in1.east) edge[fancy arrow={shape border rotate=180}{1.~Fork}]
([yshift=4mm]pro1.west);
\path
([yshift=-4mm]in1.east) edge[fancy arrow={}{6.~Pull request}] ([yshift=-4mm]pro1.west);

\path
([xshift=-7mm]start.north) edge[fancy arrow={}{2.~Clone}] 
([xshift=-7mm]in1.south);
\path
([xshift=7mm]in1.south) edge[fancy arrow={}{5.~Push}] 
([xshift=7mm]start.north);

\end{tikzpicture}
\end{document}

相关内容