2

How can I vary with the edge length of nodes on the same level? My tree is so wide it doesn't fit on a page anymore. If I would alternate with the depth of the node on depth 1, I think the tree might fit on one page.

EnergyMotivation, HealthMotivation, SleepQualityMotivation on normal distance and ShapeMotivation together with AttractivenessMotivation somewhat further away from the root.

\documentclass[11pt,a4paper,oneside,notitlepage]{book}

\usepackage{graphicx}              
\usepackage{forest}
\usepackage{rotating} 

\begin{document}
\begin{sidewaysfigure}
\centering
    \begin{forest}
    for tree={
        rectangle,
        black,
        draw,
        minimum size = 0em,
        edge={<-},
        l sep = 45pt,
        s sep = 1pt,
    },
    arrow label/.style={
        edge label={node [midway, font=\scriptsize\sffamily, sloped, above] {#1}}
    }
    [\textbf{MotivationProfile}, fill=green!20
        [EnergyMotivation, arrow label=isA, fill=green!20
            [Low, arrow label=isA, fill=green!20
                [1, rounded rectangle, arrow label=isA, fill=blue!20]
                [2, rounded rectangle, arrow label=isA, fill=blue!20]
                [3, rounded rectangle, arrow label=isA, fill=blue!20]
                [4, rounded rectangle, arrow label=isA, fill=blue!20]

            ]
            [Medium, arrow label=isA, fill=green!20
                [5, rounded rectangle, arrow label=isA, fill=blue!20]
                [6, rounded rectangle, arrow label=isA, fill=blue!20]
            ]
            [High, arrow label=isA, fill=green!20
                [7, rounded rectangle, arrow label=isA, fill=blue!20]
                [8, rounded rectangle, arrow label=isA, fill=blue!20]
                [9, rounded rectangle, arrow label=isA, fill=blue!20]
                [10, rounded rectangle, arrow label=isA, fill=blue!20]
            ]
        ]
        [ShapeMotivation, arrow label=isA, fill=green!20
            [Low, arrow label=isA, fill=green!20
                [1, rounded rectangle, arrow label=isA, fill=blue!20]
                [2, rounded rectangle, arrow label=isA, fill=blue!20]
                [3, rounded rectangle, arrow label=isA, fill=blue!20]
                [4, rounded rectangle, arrow label=isA, fill=blue!20]

            ]
            [Medium, arrow label=isA, fill=green!20
                [5, rounded rectangle, arrow label=isA, fill=blue!20]
                [6, rounded rectangle, arrow label=isA, fill=blue!20]
            ]
            [High, arrow label=isA, fill=green!20
                [7, rounded rectangle, arrow label=isA, fill=blue!20]
                [8, rounded rectangle, arrow label=isA, fill=blue!20]
                [9, rounded rectangle, arrow label=isA, fill=blue!20]
                [10, rounded rectangle, arrow label=isA, fill=blue!20]
            ]
        ]
        [HealthMotivation, arrow label=isA, fill=green!20
            [Low, arrow label=isA, fill=green!20
                [1, rounded rectangle, arrow label=isA, fill=blue!20]
                [2, rounded rectangle, arrow label=isA, fill=blue!20]
                [3, rounded rectangle, arrow label=isA, fill=blue!20]
                [4, rounded rectangle, arrow label=isA, fill=blue!20]

            ]
            [Medium, arrow label=isA, fill=green!20
                [5, rounded rectangle, arrow label=isA, fill=blue!20]
                [6, rounded rectangle, arrow label=isA, fill=blue!20]
            ]
            [High, arrow label=isA, fill=green!20
                [7, rounded rectangle, arrow label=isA, fill=blue!20]
                [8, rounded rectangle, arrow label=isA, fill=blue!20]
                [9, rounded rectangle, arrow label=isA, fill=blue!20]
                [10, rounded rectangle, arrow label=isA, fill=blue!20]
            ]
        ]
        [AttractivenessMotivation, arrow label=isA, fill=green!20
                [Low, arrow label=isA, fill=green!20
                    [1, rounded rectangle, arrow label=isA, fill=blue!20]
                    [2, rounded rectangle, arrow label=isA, fill=blue!20]
                    [3, rounded rectangle, arrow label=isA, fill=blue!20]
                    [4, rounded rectangle, arrow label=isA, fill=blue!20]

                ]
                [Medium, arrow label=isA, fill=green!20
                    [5, rounded rectangle, arrow label=isA, fill=blue!20]
                    [6, rounded rectangle, arrow label=isA, fill=blue!20]
                ]
                [High, arrow label=isA, fill=green!20
                    [7, rounded rectangle, arrow label=isA, fill=blue!20]
                    [8, rounded rectangle, arrow label=isA, fill=blue!20]
                    [9, rounded rectangle, arrow label=isA, fill=blue!20]
                    [10, rounded rectangle, arrow label=isA, fill=blue!20]
                ]
        ]
        [SleepQualityMotivation, arrow label=isA, fill=green!20
                [Low, arrow label=isA, fill=green!20
                    [1, rounded rectangle, arrow label=isA, fill=blue!20]
                    [2, rounded rectangle, arrow label=isA, fill=blue!20]
                    [3, rounded rectangle, arrow label=isA, fill=blue!20]
                    [4, rounded rectangle, arrow label=isA, fill=blue!20]

                ]
                [Medium, arrow label=isA, fill=green!20
                    [5, rounded rectangle, arrow label=isA, fill=blue!20]
                    [6, rounded rectangle, arrow label=isA, fill=blue!20]
                ]
                [High, arrow label=isA, fill=green!20
                    [7, rounded rectangle, arrow label=isA, fill=blue!20]
                    [8, rounded rectangle, arrow label=isA, fill=blue!20]
                    [9, rounded rectangle, arrow label=isA, fill=blue!20]
                    [10, rounded rectangle, arrow label=isA, fill=blue!20]
                ]
        ]
    ] 
\end{forest}
\caption{Close view on the motivation profile concept}
\label{image:ontology-motivation}
\end{sidewaysfigure}
  • welcome to tex.se! please extend your code snippet to complee small document beginning with \documentclass{...} continued with document preamble (relevant to page layout and your problem), your code fragment and end with \end{document}. – Zarko Apr 18 '18 at 12:42
2

enter image description here

  • all distances in your forest are equal, difference in positioning of the nodes 7, 8, 9 and 10 is different height of node Hight caused by letter g. this can be eliminated by defining text depth for "green" nodes.
  • in forest code blank lines are not allowed
  • in mwe below is done some improvement to your code, which make your code much shorter. since in the time, when i wrote code, your document preable was not know, i use standalone document class. you can replace it with your preamble and add missing sidewaysfigure with caption (this part of code is not essential for proposed solution):

\documentclass[margin=3mm]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{forest}
    for tree={
        rectangle,
        draw,
        if n children=0{rounded corners=2pt,fill=blue!20,
                        inner sep=2pt, anchor=north}%
                       {fill=green!20,
                        text depth=0.25ex}, % <--- solve your problem
        edge={{Straight Barb[length=2pt, width=2pt]}-},
        l sep = 45pt,
        s sep = 3pt,
    },
    arrow label/.style={
        edge label={node [pos=0.7, font=\scriptsize\sffamily,
                          inner sep=1pt, sloped, above] {#1}}
    }
    [\textbf{MotivationProfile},
        [EnergyMotivation, arrow label=isA
            [Low, arrow label=isA
                [1, arrow label=isA]
                [2, arrow label=isA]
                [3, arrow label=isA]
                [4, arrow label=isA]
            ]
            [Medium, arrow label=isA
                [5, arrow label=isA ]
                [6, arrow label=isA ]
            ]
            [High, arrow label=isA
                [7, arrow label=isA ]
                [8, arrow label=isA ]
                [9, arrow label=isA ]
                [10, arrow label=isA ]
            ]
        ]
        [ShapeMotivation, arrow label=isA
            [Low, arrow label=isA
                [1, arrow label=isA ]
                [2, arrow label=isA ]
                [3, arrow label=isA ]
                [4, arrow label=isA ]
            ]
            [Medium, arrow label=isA
                [5, arrow label=isA ]
                [6, arrow label=isA ]
            ]
            [High, arrow label=isA
                [7, arrow label=isA ]
                [8, arrow label=isA ]
                [9, arrow label=isA ]
                [10, arrow label=isA ]
            ]
        ]
        [HealthMotivation, arrow label=isA
            [Low, arrow label=isA
                [1, arrow label=isA ]
                [2, arrow label=isA ]
                [3, arrow label=isA ]
                [4, arrow label=isA ]
            ]
            [Medium, arrow label=isA
                [5, arrow label=isA ]
                [6, arrow label=isA ]
            ]
            [High, arrow label=isA
                [7, arrow label=isA ]
                [8, arrow label=isA ]
                [9, arrow label=isA ]
                [10, arrow label=isA ]
            ]
        ]
        [AttractivenessMotivation, arrow label=isA
                [Low, arrow label=isA
                    [1, arrow label=isA ]
                    [2, arrow label=isA ]
                    [3, arrow label=isA ]
                    [4, arrow label=isA ]
                ]
                [Medium, arrow label=isA
                    [5, arrow label=isA ]
                    [6, arrow label=isA ]
                ]
                [High, arrow label=isA
                    [7, arrow label=isA ]
                    [8, arrow label=isA ]
                    [9, arrow label=isA ]
                    [10, arrow label=isA ]
                ]
        ]
        [SleepQualityMotivation, arrow label=isA
                [Low, arrow label=isA
                    [1, arrow label=isA ]
                    [2, arrow label=isA ]
                    [3, arrow label=isA ]
                    [4, arrow label=isA ]
                ]
                [Medium, arrow label=isA
                    [5, arrow label=isA ]
                    [6, arrow label=isA ]
                ]
                [High, arrow label=isA
                    [7, arrow label=isA ]
                    [8, arrow label=isA ]
                    [9, arrow label=isA ]
                    [10, arrow label=isA ]
                ]
        ]
    ]
\end{forest}
\end{document}
| improve this answer | |
  • Splendid! Indeed, nice and clean code! – Ricardo Apr 18 '18 at 14:21

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.