[pgf-tikz] Dynamic Sibling distance on single level

Gaston Gloesener gaston.gloesener at web.de
Thu Apr 23 14:28:59 CEST 2020


Hello,



I started using PGF/TKIZ yesterday for drawing an unbalanced expression tree
with weights. I started from examples found in the web and thus learned by
doing. Later I found this very great over 1276 pages manual and started to
read, and the bits started to fit together and make sense an I was able to
start styling. I admit of course that I did not read all 1276 pages since
yesterday evening, but searched quite a lot in the manual and via google,
not finding any solution for my problem.



I have an unbalanced tree of 5 levels which has a problem with overlapping
nodes, trying to fix this with level based sibling sizes does not work
because it either becomes too wide or the nodes overlap. The solution would
be to change sibling distance for certain siblings only.



In the example below there are 2 nodes overlapping completely in level 3.
The solution would be simply to change the sibling distance between node "*"
and node "B" on that level, making it smaller, as this branch stops at level
4. But I found no way to achieve this. The same way I would adjust upper
levels distances for a more compact tree.



Any solution available for this case?



P.S.: please do not suggest to rearrange the tree for balancing as this is
not possible in this case!

P.P.S: The red lines are not linked to this problem, they are related to the
tree usage.



Thanks,

Gaston









\begin{tikzpicture}[level/.style={sibling distance=80mm},

                    level 1/.style={sibling distance=80mm},

                    level 2/.style={sibling distance=55mm},

                    level 3/.style={sibling distance=25mm},

                    level 4/.style={sibling distance=17mm},

                    level 5/.style={sibling distance=10mm},

                    swapme/.style={<->,red,thick},

                    every node/.style = {shape=circle,

                      draw, align=center},

                    every
label/.style={shape=rectangle,draw=none,fill=none,font=\tiny}

                    ]]

  \node {+}

    child{ node[label=below:41] (L1_1) {+}

      child{ node[label=below:29] (L2_1) {+}

        child{ node[label=below:15] (L3_1) {*}

          child{ node[label=below:9] (L4_1) {*}

            child{ node[label=below:4] (L5_1) {8}}

            child{ node[label=below:5] (L5_2) {A}}

          }

          child{ node[label=below:6] (L4_2) {B}}

        }

        child { node[label=below:14] (L3_2) {*}

          child { node[label=below:8] (L4_3) {*}

            child { node[label=below:6] (L5_3) {B}}

            child { node[label=below:2] (L5_4) {4}}

          }

          child { node[label=below:6] (L4_4) {*}

           child { node[label=below:5] (L5_5) {A}}

           child { node[label=below:1] (L5_6) {2}}

          }

        }

      }

      child { node[label=below:12] (L2_2) {*}

        child { node[label=below:6] (L3_3) {*}

          child { node[label=below:1] (L4_5) {2}}

          child { node[label=below:5] (L4_6) {A}}

        }

        child { node[label=below:6] (L3_4) {B}}

      }

    }

    child { node[label=below:14] (L1_2) {*}

      child { node[label=below:8] (L2_3) {*}

        child { node[label=below:3] (L3_5) {6}}

        child { node[label=below:5] (L3_6) {A}}

      }

      child { node[label=below:6] (L2_4) {B}}

    };

 \draw[swapme] (L5_3) -- (L5_4);

  \draw[swapme] (L5_5) -- (L5_6);

  \draw[swapme] (L4_1) -- (L4_2);

  \draw[swapme] (L4_3) -- (L4_4);

  \draw[swapme] (L3_1) -- (L3_2);

  \draw[swapme] (L3_3) -- (L3_4);

  \draw[swapme] (L2_1) -- (L2_2);

  \draw[swapme] (L2_3) -- (L2_4);

  \draw[swapme] (L1_1) -- (L1_2);

\end{tikzpicture}





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/pgf-tikz/attachments/20200423/4fec3392/attachment-0001.html>


More information about the pgf-tikz mailing list.