使用 tikz 标签箭头

使用 tikz 标签箭头

这是一个非常简单的问题,但我不知道如何在两个节点之间的箭头上添加标签。目前,我的代码似乎在我想要连接的节点之间添加了一个额外的节点,并给该节点贴上了我想要的箭头标签(这很乱)。我该如何正确地做到这一点?

\begin{center}
\begin{tikzpicture}[scale=2, every node/.style={circle, fill=blue!20, minimum size=15mm}]
\node (A) at (0, 1) {A};
\node (B) at (-1, -.5) {B};
\node (C) at (1, -.5) {C};
\draw [thick, ->] (A) to node[left] {-10} (B);
\draw [thick, ->] (A) to node[left] {15} (C);
\draw [thick, ->] (B) to node[left] {20] (C);
\end{tikzpicture}
\end{center}

输出

答案1

评论太长了。按照every node/.style={...}你的指示,TiZ 绘制全部节点带有粗体,但似乎你不希望这种情况发生在数字上。所以一种方法是

\documentclass[border=2mm,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=2, fatnode/.style={circle, fill=blue!20, minimum size=15mm}]
\node[fatnode] (A) at (0, 1) {A};
\node[fatnode] (B) at (-1, -.5) {B};
\node[fatnode] (C) at (1, -.5) {C};
\draw [thick, ->] (A) -- (B) node[midway,above left] {-10};
\draw [thick, ->] (A) -- (C) node[midway,above right] {15};
\draw [thick, ->] (B) -- (C) node[midway,above] {20};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容