\tikzstyle{vertex}=[auto=left,circle,fill=black!25,minimum size=20pt,inner sep=0pt]


      \node[vertex] (n1)  at (1,4)  {s};
      \node[vertex] (n2)  at (3,2)  {};
      \node[vertex] (n3)  at (3,3)  {};
      \node[vertex] (n4)  at (3,4)  {};
      \node[vertex] (n5)  at (3,6)  {};
      \node[vertex] (n6)  at (9,4)  {t};
      \node[vertex] (n7)  at (7,6)  {};
      \node[vertex] (n8)  at (7,4)  {};
      \node[vertex] (n9)  at (7,3)  {};
      \node[vertex] (n10) at (7,2)  {};

      \foreach \from/\to in {n1/n2,n1/n3,n1/n4,n1/n5,
      \draw[densely dotted] (\from) -- (\to);
      \foreach \from/\to in {n2/n10,n3/n9,n4/n8,n5/n7}
      \draw(\from) -- (\to);


I am trying to get vertical dots between nodes (n4,n5) and (n6,n7). I have tried many ways but nonetheless.

Also I am trying t add edge weights to the graph. I keep finding links to those written in the form of a matrix.

I need to add text representing the left and right nodes on the tree. How do we add text at desired place in the tree?

  1. To place any character, such as \dots, you can use a \path and place the required character via a node and use the sloped option so that the character is rotated along the path:

    \path (n4) -- (n5) node [red, font=\Huge, midway, sloped] {$\dots$};
    \path (n6) -- (n7) node [red, font=\Huge, midway, sloped] {$\dots$};

    If you are not satisfied with these, you could add small filled circles.

  2. The nodes at the start and end can be added and positions via a left/right option so the text is placed to the left/right of the specfic point of the node:

     \node [left ] at (n1.west) {start};
     \node [right] at (n6.east) {end};
  3. To add text above each edge you can add another option to the \foreach loop and place the text via a node:

    node [midway, above, orange] {$\weight$}

    enter image description here



\tikzstyle{vertex}=[auto=left,circle,fill=black!25,minimum size=20pt,inner sep=0pt]

  \node[vertex] (n1)  at (1,4)  {s};
  \node[vertex] (n2)  at (3,2)  {$n_2$};
  \node[vertex] (n3)  at (3,3)  {$n_3$};
  \node[vertex] (n4)  at (3,4)  {$n_4$};
  \node[vertex] (n5)  at (3,6)  {$n_5$};
  \node[vertex] (n6)  at (9,4)  {t};
  \node[vertex] (n7)  at (7,6)  {$n_7$};
  \node[vertex] (n8)  at (7,4)  {$n_8$};
  \node[vertex] (n9)  at (7,3)  {$n_9$};
  \node[vertex] (n10) at (7,2)  {$n_{10}$};

  \foreach \from/\to/\weight in {n1/n2/a, n1/n3/b, n1/n4/c, n1/n5/d,
            n6/n7/e, n6/n8/f, n6/n9/g, n6/n10/h}
  \draw[densely dotted] (\from) -- (\to) node [midway, above, orange] {$\weight$};
  \foreach \from/\to/\weight in {n2/n10/i, n3/n9/j, n4/n8/k, n5/n7/l}
  \draw(\from) -- (\to) node [midway, above, orange] {$\weight$};;

  % These are for dotted lines
  %\draw [red, dotted, ultra thick] (n4) -- (n5);
  %\draw [blue,dotted, ultra thick] (n6) -- (n7);

  \path (n4) -- (n5) node [red, font=\Huge, midway, sloped] {$\dots$};
  \path (n6) -- (n7) node [red, font=\Huge, midway, sloped] {$\dots$};

  \node [left , red] at (n1.west) {start};
  \node [right, red] at (n6.east) {end};
  • Thanks for the solution @Peter Grill. How do I add edges weights? And text that represents set of vertices? By edge weights I mean text on the edges. And the dotted vertical lines added to the graph seem more like the nodes are connected. Is there another way to do this? – user22813 Dec 2 '12 at 11:03
  • @user22813: Have updated solution to add text along the edges. I am not understanding how you want the dotted lines? – Peter Grill Dec 2 '12 at 11:10
  • I updated the solutions. I want the vertical dots between n4 and n5 in such a way that it shows that there are number of nodes like that. tex.stackexchange.com/questions/68600/… like in this. – user22813 Dec 2 '12 at 11:16
  • @user22813: If I understand correctly, you want to place \dots? That is no different than placing any other text, except that if you add the sloped option you get it placed along the required path -- have updated solution for that. – Peter Grill Dec 2 '12 at 11:40
  • Exactly what I had in mind.. Thank you so much @Peter Grill – user22813 Dec 2 '12 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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