以下代码中的树对于页面来说太宽了。如何减小树的宽度以使其适合我的页面?
\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}
答案1
增加换行符以缩小节点,并减少level distance
此处和彼处的行距,可能是最明显的做法。如您所见,您仍然有更多空间可以继续。
\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
一个流行且功能强大的绘制树的软件包是forest
。如果您感兴趣的话:
\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}
答案2
为了娱乐和锻炼(因为Torbjørn T.花一分钟时间更新我的答案,其中包含森林解决方案;然而我的答案略有不同,因此我决定在这里发布)
使用森林更简单,更简短,:-)
\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}