努力走好道路

努力走好道路

我正在尝试完成下图,我认为应该有一种简单的方法可以做到这一点\path(我能想到如何通过定义一堆坐标来实现,我试图避免这种情况)。我得到了一个放置老板的最小工作示例。任何关于如何最好地获得线条/箭头的指导都将不胜感激。我正在努力学得\path更好。

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

\begin{document}

\begin{tikzpicture}[>=stealth, myrect/.style={
    rectangle,
    draw,
    minimum width=1.5cm,
    minimum height=1cm,
    text width=1.5cm,
    align=center,
    inner xsep=1pt,
    inner ysep=1pt,
    fill=orange!30
}
]

\node[myrect] (nd1) {Site 1};
\node[myrect,right=10mm of nd1] (nd2) {Site 2};
\node[myrect,right=10mm of nd2] (nd3) {Site 3};
\node[myrect,right=10mm of nd3] (nd4) {Site 4};

\end{tikzpicture}
\end{document}

enter image description here

答案1

我不知道您有多希望它将来能够用,但这是一个可能的解决方案。

输出

figure 1

代码

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta,positioning}

\tikzset{
    myrect/.style={
    rectangle, draw,
    minimum width=2cm,
    minimum height=1cm,
    text width=1.5cm,
    align=center,
    inner xsep=1pt,
    inner ysep=1pt,
    fill=orange!30,
    text=blue!80!black
    },
    smn/.style={circle,fill=blue!80!black, inner sep=1pt, outer sep=2pt, text=white, font=\scriptsize},
    arr/.style={->, >={Latex[length=2mm, width=1.5mm]}, #1, line width=.5mm}
}

\begin{document}
\begin{tikzpicture}

\node[myrect] (nd1) {Site 1};
\node[myrect,right=10mm of nd1] (nd2) {Site 2};
\node[myrect,right=10mm of nd2] (nd3) {Site 3};
\node[myrect,right=10mm of nd3] (nd4) {Site 4};

\node[above=1.5cm of nd1,text=blue!80!black] (uc) {updates commit}; 

% arrows

\draw[arr=blue!80!black] (uc.200) -- (uc.200|-nd1.north) node[left,midway,smn] (A) {1};
\draw[arr=blue!80!black] (A) -- (A-|nd4.145) -- (nd4.145|-nd4.north);
\draw[arr=blue!80!black] (A-|nd2.145) -- (nd2.145|-nd2.north) node[right,midway,smn] {2};;
\draw[arr=blue!80!black] (A-|nd3.145) -- (nd3.145|-nd3.north);

\draw[arr=red] (nd4.45) -- (nd4.45|-A.north) -- (A.north-|uc.330) -- (uc.330) node[right,pos=.7,smn] {3};
\draw[arr=red, -, shorten <=2mm] (uc.330) -- (uc.330|-nd1.north);
\draw[arr=red, -] (nd2.45) -- (nd2.45|-A.north);
\draw[arr=red, -] (nd3.45) -- (nd3.45|-A.north);
\end{tikzpicture}
\end{document}

答案2

你可以使用foreach它们。这里我使用常规路径,因为我们需要在每个路径上放置箭头,但是如果你想让路径更短,那么你可以使用路径或边缘等。

% \usetikzlibrary{arrows,positioning} %<---Preamble
\begin{tikzpicture}[>=stealth, myrect/.style={
    rectangle,
    draw,
    minimum width=1.5cm,
    minimum height=1cm,
    text width=1.5cm,
    align=center,
    inner xsep=1pt,
    inner ysep=1pt,
    fill=orange!30
}]

\node[myrect] (nd1) {Site 1};
\foreach \x[count=\xi] in {2,3,4}{\node[myrect,right=10mm of nd\xi] (nd\x) {Site \x};}
\draw[blue,thick] (nd1.120) ++(0,5mm)--++(0,5mm);
\foreach \x in{1,...,4}{\draw[blue,thick,-latex]([yshift=5mm]nd1.120) -| (nd\x.120);}
\draw[red,thick,-latex]\foreach\x in{1,...,4}{(nd\x.60) |- ([yshift=7mm]nd1.60)} --++(0,5mm);

\end{tikzpicture}

enter image description here

相关内容