在 Tikz 中的箭头内插入文本

在 Tikz 中的箭头内插入文本

我想在两个节点(a)和(b)之间画一个箭头,并在箭头内写文字。我该如何修改此命令来控制箭头的大小并插入文字?

\draw[->, >=latex, blue!20!white, line width=15pt]   (a) to (b) ; 

答案1

您可以完美地使用形状库来实现这一点。使用\usetikzlibrary{shapes.arrows}。基于 TikZ 手册第 441 页中的示例:

\documentclass{article}

\usepackage{tikz}
    \usetikzlibrary{shapes.arrows}

\begin{document}
    \begin{tikzpicture}[every node/.style={single arrow, draw=none, rotate=60}]
        \node [fill=red!50] {arrow 1};
        \node [fill=blue!50, single arrow head indent=1ex] at (1.5,0) {arrow 2};
    \end{tikzpicture}
\end{document}

得出:

在此处输入图片描述

答案2

这是两个完全不同的问题,回答标题中的问题:

如果您只是node沿线添加,它将打印在线的顶部(除非另有指定)。但是您必须更改颜色,因为命令的颜色规范\draw也适用于节点。

对于非水平箭头,请添加slopednode选项中。

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (6,0);
\coordinate (c) at (45:6);

\draw[->, >=latex, blue!20!white, line width=15pt] (a) to node[black]{text} (b);
\draw[->, >=latex, blue!20!white, line width=15pt] (a) to node[black,sloped]{text} (c);
\end{tikzpicture}
\end{document}

相关内容