我已经尝试过这个代码:
\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 Groups
pgfmanual 中的 部分
\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}