Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am creating a graph of connected nodes and I want to have numbers on all edges that connect the nodes. At the moment it looks as follows:

\begin{figure}[H]
\begin{tikzpicture}
\node[shape=ellipse, draw=black, fill=gray!50] (a) at (7,-4) {a};
\node[shape=ellipse, draw=black, fill=gray!50] (b) at (7,1) {b};
\draw[solid] (b) -- (a) ;
\end{tikzpicture}
\end{figure}

If I want the line between a and b have an assigned number, how shall I do?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Something like this? The key is use of node

\draw[solid] (b) --node[pos=xx,position](){3}(a) ;

where xx=0~1 and position= left,right,above,below

enter image description here

Code

\documentclass[tikz,border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,}

\begin{document}
%\begin{figure}[H]
\begin{tikzpicture}
\node[shape=ellipse, draw=black, fill=gray!50] (a) at (7,-4) {a};
\node[shape=ellipse, draw=black, fill=gray!50] (b) at (7,1) {b};
\draw[solid] (b) --node[midway,right](){1} (a) ;
\draw[solid] (b) --node[pos=0.1,left](){2} (a) ;
\draw[solid] (b) --node[pos=0.9,right](){3}(a) ;
\end{tikzpicture}
%\end{figure}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.