我正在尝试在 Tikzpicture 中绘制一系列标记节点,到目前为止我已经:
\begin{tikzpicture}[box/.style = {draw, semithick, minimum size=1cm}]
\node at (0, 3*3) [box] (0) {Node};
\node at (0, 3*2) [box] (1) {Node};
\node at (0, 3*1) [box] (2) {Node};
\node at (0, 3*0) [box] (3) {Node};
\draw (0) -> (1) node [midway, fill=white] {Label 1};
\draw (1) -> (2) node [midway, fill=white] {Label 2};
\draw (2) -> (3) node [midway, fill=white] {Label 3};
\end{tikzpicture}
但不幸的是,尽管我在 SO 和搜索引擎上查找过,我还是无法弄清楚如何获得箭头而不是直线。我应该使用什么格式来实现这一点?
答案1
这里我在代码中放了三个不同的箭头。你要告诉 Ti钾Z 如何在方括号中绘制箭头和其他内容\draw
。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[box/.style = {draw, semithick, minimum size=1cm}]
\node at (0, 3*3) [box] (0) {Node};
\node at (0, 3*2) [box] (1) {Node};
\node at (0, 3*1) [box] (2) {Node};
\node at (0, 3*0) [box] (3) {Node};
\draw[->] (0) -- (1) node [midway, fill=white] {Label 1};
\draw[-latex] (1) -- (2) node [midway, fill=white] {Label 2};
\draw[-stealth] (2) -- (3) node [midway, fill=white] {Label 3};
\end{tikzpicture}
\end{document}
答案2
作为补充土拨鼠回答一下,节点放置的替代代码:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[box/.style = {draw, semithick, minimum size=1cm}]
\node at (0, 3*3) [box] (0) {Node};
\node at (0, 3*2) [box] (1) {Node};
\node at (0, 3*1) [box] (2) {Node};
\node at (0, 3*0) [box] (3) {Node};
\draw[->] (0) -- node [fill=white] {Label 1} (1) ;
\draw[-latex] (1) -- node [fill=white] {Label 2} (2) ;
\draw[-stealth] (2) -- node [fill=white] {Label 3} (3) ;
\end{tikzpicture}
\end{document}
结果是一样的。