I am trying to draw a graph with node and edge weights. Here is what I've managed to do so far. I've placed node names. but I want to place node weights under the circles. And I want to put edge weights too. I am not getting anywhere how to put edge label. Here is my current code.
\begin{tikzpicture}[transform shape]
\node[vertex][](t) at (2, 0) {$ \omega_{i} $};
\node[vertex][](r1) at (1, 2) {$ r^{\omega_{i}}_{1} $};
\node[vertex][](r2) at (3, 2) {$ r^{\omega_{i}}_{2} $};
\node[vertex][](q1) at (0,-2) {$ q^{\omega_{i}}_{1} $};
\node[vertex][](q2) at (2,-2) {$ q^{\omega_{i}}_{2} $};
\node[vertex][](q3) at (4,-2) {$ q^{\omega_{i}}_{2} $};
\begin{scope}[every path/.style={-, dashed}]
\draw (t) -- (q1);
\draw (t) -- (q2);
\draw (t) -- (q3);
\draw (t) -- (r1);
\draw (t) -- (r2);
\end{scope}
\begin{scope}[every path/.style={-}]
\draw (r1) -- (q1);
\draw (r1) -- (q2);
\draw (r1) -- (q3);
\draw (r2) -- (q1);
\draw (r2) -- (q2);
\draw (r2) -- (q3);
\end{scope}
\end{tikzpicture}
Best Answer
You can add an edge label like this:
\draw (t) -- node [anchor=south] {$p_1$} (q1)
. You will have to play around a bit with getting the anchors right (choosenorth
,south west
, etc., to see the effect). Other parameters you may want to look at isinner sep
(which is the white space around the label) andpos
(which determines where on the edge the label will appear).Adding node weights can be done by
\node[vertex, label=below:$10$](t) at (2, 0) {$ \omega_{i} $};
(also note that you don't need the extra[]
).Here you go:
If you want your edge labels to be rotated automatically, you can use
sloped
: