3

In the following code the tree is too wide for the page. How can I decrease the width of the tree to make it fit on my page?

\documentclass{scrartcl}

\usepackage{showframe}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}[grow=right,
    level 1/.style={sibling distance=45mm, level distance=28mm},
    level 2/.style={sibling distance=30mm, level distance=30mm},
    level 3/.style={sibling distance=33mm, level distance=25mm},
    level 4/.style={sibling distance=20mm, level distance=28mm},
    level 5/.style={sibling distance=15mm, level distance=25mm}, 
    level 6/.style={sibling distance=15mm, level distance=23mm},
    every node/.style = {shape=rectangle, rounded corners, draw, align=center, top color=white, bottom color=green!15}]
    \node {Turbine}
    child { node {Blades} 
        child { node {Stator 1 -- n}
            child { node {Leading\\Edge} 
                child{ node{Station\\Data} }
                child{ node {Radial\\Profile}
                    child{ node {Point 1 -- n} }
                }
            }
            child { node {Trailing\\Edge} 
                child{ node{Station\\Data} }
                child{ node {Radial\\Profile}
                    child{ node {Point 1 -- n} }
                }
            }
            child { node {Upstream\\Stations} 
                child { node {Station 1 -- n }
                    child{ node{Station\\Data} }
                    child{ node {Radial\\Profile}
                        child{ node {Point 1 -- n} }
                    }
                }
            }
            child { node {Internal\\Stations} 
                child { node {Station 1 -- n }
                    child{ node{Station\\Data} }
                    child{ node {Radial\\Profile}
                        child{ node {Point 1 -- n} }
                    }
                }
            }
        }
    }
    child { node {Stage Definitions} }
    child { node {Downstream\\Stations}
        child { node {Station 1 -- n }
            child{ node{Station\\Data} }
            child{ node {Radial\\Profile}
                child{ node {Point 1 -- n} }
            }
        }
    };
    \end{tikzpicture}
\end{document}

2 Answers 2

3

More line breaks to make narrower nodes, and reducing the level distance here and there, are perhaps the most obvious things to do. As you can see, you still have a bit more space to go on.

enter image description here

\documentclass{scrartcl}

\usepackage{showframe}
\usepackage{tikz}

\begin{document}
\begin{center}
\begin{tikzpicture}[grow=right,
    level 1/.style={sibling distance=45mm, level distance=20mm},
    level 2/.style={sibling distance=30mm, level distance=25mm},
    level 3/.style={sibling distance=33mm, level distance=20mm},
    level 4/.style={sibling distance=20mm, level distance=20mm},
    level 5/.style={sibling distance=15mm, level distance=20mm}, 
    level 6/.style={sibling distance=15mm, level distance=15mm},
    every node/.style = {
      shape=rectangle,
      rounded corners,
      draw,
      align=center,
      top color=white,
      bottom color=green!15,
    }
]
    \node {Turbine}
    child { node {Blades} 
        child { node {Stator\\1 -- n}
            child { node {Leading\\Edge} 
                child{ node{Station\\Data} }
                child{ node {Radial\\Profile}
                    child{ node {Point\\1 -- n} }
                }
            }
            child { node {Trailing\\Edge} 
                child{ node{Station\\Data} }
                child{ node {Radial\\Profile}
                    child{ node {Point\\1 -- n} }
                }
            }
            child { node {Upstream\\Stations} 
                child { node {Station\\1 -- n }
                    child{ node{Station\\Data} }
                    child{ node {Radial\\Profile}
                        child{ node {Point\\1 -- n} }
                    }
                }
            }
            child { node {Internal\\Stations} 
                child { node {Station\\1 -- n }
                    child{ node{Station\\Data} }
                    child{ node {Radial\\Profile}
                        child{ node {Point\\1 -- n} }
                    }
                }
            }
        }
    }
    child { node {Stage\\Definitions} }
    child { node {Downstream\\Stations}
        child { node {Station\\1 -- n }
            child{ node{Station\\Data} }
            child{ node {Radial\\Profile}
                child{ node {Point 1 -- n} }
            }
        }
    };
    \end{tikzpicture}
\end{center}
\end{document}

forest

A popular and powerful package for drawing trees is forest. In case you might be interested:

forest version

\documentclass{scrartcl}

\usepackage{showframe}
\usepackage{forest}
\tikzset{
  treenode/.style={
      shape=rectangle,
      rounded corners,
      draw,
      align=center,
      top color=white,
      bottom color=green!15
  }
}
\begin{document}
\begin{center}
\begin{forest}
for tree={%
  treenode,
  grow'=east}
%
[ Turbine
  [ Downstream\\Stations
    [ Station\\1--n
      [ Radial Profile
        [ Point\\1--n ]
      ]
      [ Station\\Data ]
    ]
  ]
  [ Stage\\definitions, before computing xy={s/.average={s}{siblings}}]
  [ Blades
    [ Station\\1--n
      [ Leading\\edge
        [ Station\\data ]
        [ Radial\\profile
          [ Point\\1--n ]
        ]
      ]
      [ Trailing\\edge
        [ Station\\data ]
        [ Radial\\profile
          [ Point\\1--n ]
        ]
      ]
      [ Upstream\\stations
        [ Station\\1--n
          [ Station\\data ]
          [ Radial\\profile
            [ Point\\1--n ]
          ]
        ]
      ]
      [ Internal\\stations
        [ Station\\1--n
          [ Station\\data ]
          [ Radial\\profile
            [ Point\\1--n ]
          ]
        ]
      ]
    ]
  ]
]
\end{forest}
\end{center}
\end{document}
4
  • I have an additional question: Is it possible to change the textsize of the tree?
    – NelDav
    Commented Mar 14, 2018 at 13:01
  • @Ahrtaler Add font=\footnotesize (or some other size switching command) to the every node style (or the treenode style, if you're looking at the forestexample). Commented Mar 14, 2018 at 13:02
  • With \footnotesize it works, but what is the size switching command to switch the size to exact 10pt ?
    – NelDav
    Commented Mar 14, 2018 at 13:20
  • @Ahrtaler \small, in this specific case (tex.stackexchange.com/questions/24599), more generally \fontsize{10pt}{12pt}\selectfont (tex.stackexchange.com/questions/48276). Commented Mar 14, 2018 at 13:31
2

for fun and exercises (since Torbjørn T. beat me for one minute with update of is answer with forest solution; however my is slightly different so i decide after all to publish here)

with forest is simpler and shorter, :-)

\documentclass{scrartcl}
\usepackage[edges]{forest}
\usetikzlibrary{shadows}
\parindent=0pt
%------------- show page layout. don't use this in real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{forest}
    for tree={              % style of nodes in the tree
      draw, semithick, drop shadow, %rounded corners,
   minimum height = 11mm,
             font = \small,
        top color = teal!10,
     bottom color = teal!50,
            align = center,
                            % style of tree (edges, distances, direction)
           anchor = west,
             grow = east,
    forked edge,            % for forked edge
            s sep = 4mm,    % sibling distance
            l sep = 8mm,    % level distance
         fork sep = 4mm,    % distance from parent to branching point
               }% end for tree
[Turbine
    [Blades
        [Stator\\ 1 -- n
            [Leading\\Edge
                [Station\\Data]
                [Radial\\Profile
                    [Point\\ 1 -- n]
                ]
            ]
            [Trailing\\Edge
                [Station\\Data]
                [Radial\\Profile
                    [Point\\ 1 -- n]
                ]
            ]
            [Upstream\\Stations
                [Station\\ 1 -- n
                    [Station\\Data]
                    [Radial\\Profile
                        [Point\\ 1 -- n]
                    ]
                ]
            ]
            [Internal\\Stations
                [Station\\ 1 -- n
                    [Station\\Data]
                    [Radial\\Profile
                        [Point\\ 1 -- n]
                    ]
                ]
            ]
        ]
    ]
    [Stage\\ Definitions,fit=band]% before computing xy={s/.average={s}{siblings}}]
    [Downstream\\Stations
        [Station\\ 1 -- n
            [Station\\Data]
            [Radial\\Profile
                [Point\\ 1 -- n]
            ]
        ]
    ]
];
    \end{forest}
\end{document}

enter image description here

You must log in to answer this question.

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