TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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.