I want to draw the physical model of graph that has a ball for each vertex and a piece of string for each edge. In this model, if you lift a ball high enough, the other balls are pulled up along with it, affected by both the stress of strings and gravity. An illustration is shown in the following figure.


However, using tikz-qtree, I can only draw an ordinary tree which cannot visualize the strings or gravity (and is somewhat ugly).


Therefore, I want to know that

How to draw the physical tree with balls under both the stress of strings and gravity?

My code using tikz-qtree is as follows.



  \node [draw, circle] (r) at (0,0) {$r$};
  \node [draw, circle, blue, very thick] (s) at (2,0) {$s$};
  \node [draw, circle] (t) at (4,0) {$t$};
  \node [draw, circle] (u) at (6,0) {$u$};

  \node [draw, circle] (v) at (0,-2) {$v$};
  \node [draw, circle] (w) at (2,-2) {$w$};
  \node [draw, circle] (x) at (4,-2) {$x$};
  \node [draw, circle] (y) at (6,-2) {$y$};

  \draw (r) to (v);
  \draw (r) to (s);
  \draw (s) to (w);
  \draw (t) to (u);
  \draw (t) to (w);
  \draw (t) to (x);
  \draw (u) to (x);
  \draw (u) to (y);
  \draw (x) to (y);
  \draw (y) to (u);

  \tikzset{level distance = 36pt, sibling distance = 25pt}
  \tikzset{every node/.style = {draw, circle}}

  \Tree [.\node[blue, very thick](s){$s$}; 
            [.$r$ $v$ ]
                [.\node(t){$t$}; \node(u){$u$}; ] 
                [.\node(x){$x$}; \node(y){$y$}; ]

  % cross edges
  \draw [dashed, thick, red] (t) to [out = -45, in = 225] (x);
  \draw [dashed, thick, red] (u) to [out = -45, in = 225] (y);
  \draw [dotted, thick, purple] (x.-110) to (u);

  • You might want to check out the tkz-graph package. Documentation in French, but with lots of examples to play with. It doesn't do exactly what you want, but it is designed for graphs and not trees; anything you do with tikz-qtree will likely be very hacky, since it's not designed for that. See also Multi-rooted Tree-like Structures and Nodes with Multiple Parents in LaTeX.
    – Alan Munn
    Nov 18, 2014 at 6:30
  • @AlanMunn Thanks. It seems more suitable for my purpose. I will check it carefully later. The hardest part (IMO) is to determine the positions of the balls under gravity.
    – hengxin
    Nov 18, 2014 at 6:53
  • I don't get the question exactly. Do you want to know how to draw those bent lines connecting the nodes? If yes, I have an answer.
    – user11232
    Nov 18, 2014 at 7:41
  • @HarishKumar "Bent lines connecting nodes" is one aspect. The other aspect is how to put the balls in a common subtree at the same layer closely next to each other (due to strings and gravity).
    – hengxin
    Nov 18, 2014 at 7:56
  • 2
    The new version of TikZ 3.00 has electrical charge and spring tension properties for the placement of graph elements.
    – percusse
    Nov 18, 2014 at 8:34

1 Answer 1


Here's some examples with the graph drawing stuff from the latest PGF version. I'm not quite sure about the best way to define new edges but at least the method I used seems to work. It requires lualatex:


 edge squiggle/.style={
   new --/.code n args={4}{
    \path [-, every new --/.try]
      edge[##3, decoration=squiggle, decorate] ##4
  edge loop/.style={
   new --/.code n args={4}{
    \draw [-, every new --/.try]
      edge [out=260, in=280, looseness=3] ##4

\tikz\graph [nodes={shape=circle, fill=gray!50}, edge squiggle, 
  chain shift=(0:2cm), group shift=(270:2cm)]{
  E -- S -- A;
  D -!- C -- B;
  D -- E; D -- S;
  C -- S; B -- A; 


\tikz\graph [layered layout, nodes={shape=circle, fill=gray!50},
  level distance=1.5cm] {
  S -- {A -- B, C -- B, E, D};
  {[edge loop] E -- D};
  {[same layer] A, C, D, E};

enter image description here

  • 1
    Actually I suppose the second row of nodes in the graph on the right should have no space between them. Nov 18, 2014 at 14:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .