4

Here is my tree diagram built using forest package.

forest tree

How to move the node in the red pen to the position of the blue pen?

Here is my code.

\begin{forest}
    for tree={calign=last},
    [HEAD
        [tag,no edge]
        [branch
            [commit
                [commit
                    [tree
                        [tree
                            [tree
                                [tree
                                    [blob]]
                                [blob]]
                            [blob]]]]
                [tree
                    [tree
                        % [shared blob here]
                        [tree
                            % [shared blob here]
                            [blob]]]]]]]
\end{forest}

Thank you very much.

  • 1
    Welcome to TeX.SX! – Bobyandbob Nov 5 '18 at 5:52
  • Hi @Bobyandbob, I'm new here and I'm also a newbie in LaTeX. Thank you! – Daniel Nov 5 '18 at 13:52
2

Rather than adding the second "commit" as a child of first "commit" node you can insert it at the same level with them.

\documentclass{article} 
\usepackage{forest}

\begin{document}
\begin{forest}
    for tree={calign=last},
    [HEAD
        [tag,no edge]
        [branch
            [commit,no edge,tikz={\draw()--(!n);}
                    [tree
                        [tree
                            [tree
                                [tree
                                    [blob]]
                                [blob]]
                            [blob]]]]
            [commit
                [tree
                    [tree
                        % [shared blob here]
                        [tree
                            % [shared blob here]
                            [blob]]]]]]]
\end{forest}
\end{document}

enter image description here

  • Very nice! +1. This is the first time I've encountered the syntax tikz={\draw()--(!n); Did it come from tikz or forest? Can you tell me where I can find documentation about it? If not, can you explain it? – AndréC Nov 5 '18 at 13:39
  • 1
    First forest is a pgf/TikZ-based package, you can add a tikz code at any level with key tikz or at the end of tree (before \end{forest}), for '()' in \draw() it refere to the current node and (!n) to the next sibling. – Salim Bou Nov 5 '18 at 14:52
  • Thank you very much for your answer. I looked for documentation on the TikZ manual version 3.0.1a as well as the manual 1.18 on \draw() and this notation is used without being documented. On the other hand, the notation (!n) is neither used nor documented. Do you know in which version of Tikz these codes are documented? – AndréC Nov 5 '18 at 18:25
  • Those notations are from forest not from tikz mirrors.ctan.org/graphics/pgf/contrib/forest/forest-doc.pdf – Salim Bou Nov 5 '18 at 19:24
  • 1
    Take a look at the forest manual pages 8 and 57. – Salim Bou Nov 6 '18 at 5:19

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.