12

This is a super simple problem, but I can't figure out how to add a label to an arrow between two nodes. Right now, the code I have seems to add an extra node in between the nodes I wish to connect and labels that node what I want to label the arrow (and it makes a mess). How can I do this properly?

\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}

Output

6
  • This is (probably) due to all the to node[left] {-10} things.
    – user121799
    Apr 23, 2018 at 21:53
  • Well yeah, but that's what I've seen people use in examples online...
    – Nick
    Apr 23, 2018 at 21:53
  • Try \draw [thick, ->] (A) -- (B); \draw [thick, ->] (A) -- (C); \draw [thick, ->] (B) -- (C); instead.
    – user121799
    Apr 23, 2018 at 21:54
  • But how do I add a little label on the arrows with the numbers?
    – Nick
    Apr 23, 2018 at 21:54
  • 1
    Well yes, but how could I add a label on the arrows?
    – Nick
    Apr 23, 2018 at 22:01

1 Answer 1

18

Too long for a comment. With every node/.style={...} you instructed TikZ to draw all nodes with a fat bullet, but it seems like you don't want this to happen for the numbers. So one way to go is

\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}

enter image description here

1
  • 2
    This is my final upvote.
    – Sebastiano
    Apr 23, 2018 at 22:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .