这是我按照以下代码制作的一棵树:
\begin{tikzpicture}[sibling distance=7em,
every node/.style = {shape=rectangle, rounded corners,
draw,
top color=white, bottom color=blue!20}]]
\node {$ C_{i} $}
child { node {$ q_{1}k_{1} $}
child{node{$q_{2}k_{2} $}}
child{node{$\cdots$}}
child{node{$q_{2}k_{2}+(k_{2}-1) $}}}
child { node {$ \cdots$} }
child { node {$ q_{1}k_{1} +(k_{1}-1)$}
child{node{$q_{2}k_{2} $}}
child{node{$\cdots$}}
child{node{$q_{2}k_{2}+(k_{2}-1) $}}}
;
\end{tikzpicture}
正如你所看到的,两个树枝倒塌了,我想让树变得更宽,变得更漂亮。
答案1
我同意 Alan Munn 的观点,你可能想切换到forest
。以下是两种变体,可以说明它的一些选项。
\documentclass{article}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={shape=rectangle, rounded corners,calign=child,calign primary child=2,
draw, top color=white, bottom color=blue!20,math content}
[C_{i}
[q_{1}k_{1}
[q_{2}k_{2}]
[\cdots]
[{q_{2}k_{2}+(k_{2}-1)}]
]
[\cdots[,phantom]]
[{q_{2}k_{2}+(k_{2}-1)}
[q_{2}k_{2}]
[\cdots]
[{q_{2}k_{2}+(k_{2}-1)}]
]
]
\end{forest}
or
\tikzset{cbox/.style={shape=rectangle, rounded corners,
draw, top color=white, bottom color=blue!20},
none/.style={draw=none,shade=none},
Dotted/.style={% https://tex.stackexchange.com/a/52856/194703
dash pattern=on 0.1pt off 2mm,line cap=round,line width = 2pt,
shorten <=2.5mm,shorten >=2.5mm}}
\begin{forest}
for tree={math content,calign=child,calign primary child=2,cbox}
[C_{i}
[q_{1}k_{1},alias=left1
[q_{2}k_{2},alias=left2]
[,phantom]
[{q_{2}k_{2}+(k_{2}-1)},alias=right2]
]
[,phantom[,phantom]]
[{q_{2}k_{2}+(k_{2}-1)},alias=right1
[{q_{2}k_{2}+(k_{2}-1)},alias=left3]
[,phantom]
[q_{2}k_{2},alias=right3]
]
]
\foreach \X in {1,2,3} {\draw[Dotted](left\X.east) -- (right\X.west);}
\end{forest}
\end{document}