[Tex/LaTex] Getting vdots in graph tree

diagramstikz-trees

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{tikz}
\tikzstyle{vertex}=[auto=left,circle,fill=black!25,minimum size=20pt,inner sep=0pt]

\begin{document}    

\begin{tikzpicture}
      \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,
                n6/n7,n6/n8,n6/n9,n6/n10}
      \draw[densely dotted] (\from) -- (\to);
      \foreach \from/\to in {n2/n10,n3/n9,n4/n8,n5/n7}
      \draw(\from) -- (\to);
      \end{tikzpicture}

\end{document}

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?

Best Answer

  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

Code:

\documentclass[border=2pt]{standalone}
\usepackage{tikz}

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

\begin{document}
\begin{tikzpicture}
  \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};
\end{tikzpicture}
\end{document}
Related Question