2
  • I'm not super comfortable (yet) with forest.
  • I have a problem with the alignment of nodes.
  • Where am I wrong?

enter image description here

\documentclass[border=2mm]{standalone}
\usepackage{forest}

\begin{document}
\begin{forest}
    box/.style={rounded corners, 
        draw=gray!50, 
        fill=orange!20,
        font=\sffamily,
        minimum height=2em},
    [Actions, box 
        [Common shares, box
            [porte 
                [Droits de vote, box 
                    [donne droit à 
                        [Une voix à l'élection du board, box]
                    ]
                ]
            ]
            [peut donner droit à
                [Dividendes, box,name=div
                    [distribue
                        [Part des profits, box]
                    ]
                    [décidé par,name=decision
                        [Le Board, box, name=dir]
                    ]
                ]
            ]
        ]
        [Actions préférentielles, box
            [donne droit à,  name=droit]
        ]
    ]
    \draw (droit)--(div);
\end{forest}
                                    
\end{document}

PS: side question on the go... how can I get smaller fonts when not in a box/.style?

2
  • Use for tree={text depth=0.25ex,minimum height=2em}.
    – user238301
    Apr 3, 2021 at 19:17
  • @user238301 merci unknown user :)
    – JeT
    Apr 3, 2021 at 19:19

2 Answers 2

3

To align the texts, add an appropriate text depth. To get an alternating pattern of boxed and non-boxed nodes, use the isodd function.

\documentclass[border=2mm]{standalone}
\usepackage{forest}

\begin{document}
\begin{forest}
    box/.style={rounded corners, 
        draw=gray!50, 
        fill=orange!20,
        font=\sffamily,
        },
    for tree={text depth=0.25ex,
    if={level==0||isodd(level)==1}{box,minimum height=2em}{minimum height=1.2em}}   
    [Actions
        [Common shares
            [porte 
                [Droits de vote 
                    [donne droit à 
                        [Une voix à l'élection du board]
                    ]
                ]
            ]
            [peut donner droit à
                [Dividendes, name=div
                    [distribue
                        [Part des profits]
                    ]
                    [décidé par,name=decision
                        [Le Board, name=dir]
                    ]
                ]
            ]
        ]
        [Actions préférentielles
            [donne droit à,  name=droit]
        ]
    ]
    \draw (droit)--(div);
\end{forest}
                                    
\end{document}

enter image description here

4

You only need to define anchors of node:

\documentclass[border=2mm]{standalone}
\usepackage{forest}

\begin{document}
\begin{forest}
    box/.style={
        rounded corners,
        draw=gray!50,
        fill=orange!20,
        font=\sffamily,
        minimum height=2em,
        anchor=north    % or center <---- added
        },
    for tree = {
    if level =  2{}{if level = 4{}{box}}
                }
    [Actions
        [Common shares
            [porte
                [Droits de vote
                    [donne droit à
                        [Une voix à l'élection du board]
                    ]
                ]
            ]
            [peut donner droit à
                [Dividendes, name=div
                    [distribue
                        [Part des profits]
                    ]
                    [décidé par, name=decision
                        [Le Board, name=dir]
                    ]
                ]
            ]
        ]
        [Actions préférentielles
            [donne droit à,  name=droit]
        ]
    ]
    \draw (droit)--(div);
\end{forest}

\end{document}

enter image description here

Edit: To forest code is added specification for tree which prescribe nodes style depending from level, where they are.

3
  • Eagle eye ! merci :) But do you notice the text in nodes still don't align ?
    – JeT
    Apr 3, 2021 at 19:04
  • @JeT, see edited answer. I added some trick, which defined nodes stlyle according to level in which they are.
    – Zarko
    Apr 3, 2021 at 19:13
  • merci Mr Z ! works prefectly.
    – JeT
    Apr 3, 2021 at 19:25

You must log in to answer this question.

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