TransWikia.com

Visual issue when printing edge weights in tikz

TeX - LaTeX Asked on January 23, 2021

I am trying to place edge weight in a network that I draw in tikz, however, it does not show up as I wanted.

I am providing a MWE below.

documentclass{standalone}

usepackage{tikz}

begin{document}
begin{tikzpicture}[scale=.35,auto=left,minimum size=2mm ,every node/.style={circle,fill=black}, text=white, minimum size=0.3 cm,  font = scriptsize]
     node (v1) at (5,6) {C};
     node (v2) at (-1,6) {B};
     draw  (v1) edge node{1} (v2);
end{tikzpicture}
end{document}

Why does the edge weight show up like a node? How can I solve this issue?

One Answer

Well, it is a node, and you've set every node/.style={...} in the options to the tikzpicture ...

One workaround is to use a scope environment and set every node for that.

enter image description here

documentclass{standalone}

usepackage{tikz}

begin{document}
begin{tikzpicture}[
  scale=.35,
  auto=left,
%  minimum size=0.3 cm,
  font = scriptsize
  ]

begin{scope}[every node/.style={circle,fill=black, text=white,}]
     node (v1) at (5,6) {C};
     node (v2) at (-1,6) {B};
end{scope}
     draw  (v1) edge node{1} (v2);
end{tikzpicture}
end{document}

Correct answer by Torbjørn T. on January 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP