Tikz - 绘制箭头路径

Tikz - 绘制箭头路径

我需要绘制这样的箭头路径: 目标

我已经尝试过这个代码:

\documentclass[tikz, border=2mm]{standalone}
\begin{document}
    \begin{tikzpicture}[scale=2]
        \node[circle, draw=black] (A) at (0,0){A};
        \node[circle, draw=black] (B) at (1,0){B};
        \node[circle, draw=black] (C) at (2,0){C};
        \node[circle, draw=black] (D) at (3,0){D};
        \draw[->] (A) -- (B) -- (C) -- (D);
    \end{tikzpicture}
\end{document}

但我有类似的东西:

通过代码

怎么做 ?

编辑:我更改了帖子

答案1

更新:使用图库

graphs库允许您以简单而简洁的方式执行此操作。请参阅19.2.2 Concept: Chain Groupspgfmanual 中的 部分截屏

\documentclass[tikz, border=5mm]{standalone}
\usetikzlibrary {graphs} 

\begin{document}

\tikz\graph[grow right=20mm,nodes={draw, circle,fill=cyan!30}] {A -> B -> C -> D};

\end{document}

第一个答案:使用 chains 库

chains库允许您执行此操作。请section 48 Chains参阅pgfmanual

截屏

\documentclass[tikz, border=2mm]{standalone}
 \usetikzlibrary {chains} 

\begin{document}
\begin{tikzpicture}[node distance=20mm, on grid,
every node/.style=draw,circle,every join/.style=->]
\begin{scope}[start chain]
\node [draw,on chain,join] {A};
\node [draw,on chain,join] {B};
\node [draw,on chain,join] {C};
\node [draw,on chain,join] {D};
\end{scope}
\end{tikzpicture}
    
\end{document}

答案2

与@AndréC 的答案(+1)类似,但代码稍短一些:

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{arrows.meta,
                chains}

\begin{document}
\begin{tikzpicture}[
node distance = 20mm, on grid,
  start chain = going right,
every node/.style = {circle, draw, on chain, join=by -{Straight Barb[scale=0.8]}}
                    ]
\node {A};
\node {B};
\node {C};
\node {D};
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容