我正在尝试使用 tikz 生成树形图,其中节点中的文本垂直和水平居中。第二个可以工作,但文本没有垂直对齐,尽管我使用了“文本居中”。这是我的代码:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
grow = right,
level 1/.style={sibling distance=1.5cm,level distance=4.5cm},
edge from parent/.style={thick,draw=blue!40!black!60},
every node/.style = {shape=rectangle, rounded corners, thick,
draw=blue!40!black!60, align=center,
top color=white, bottom color=black!20!white,
text centered, text width=2.75cm, text height = 0.5cm}]]
\node {Question}
child { node {\small Question}}
;
\end{tikzpicture}
\end{document}
这将产生以下内容:
知道我在这里做错了什么吗?
答案1
在文中使用minimum height
andfont=\small
代替。\small
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
grow = right,
level 1/.style=
{
sibling distance=1.5cm,
level distance=4.5cm
},
edge from parent/.style=
{
thick,
draw=blue!40!black!60
},
every node/.style =
{
shape=rectangle,
rounded corners,
thick,
draw=blue!40!black!60,
align=center,
font=\small,
top color=white,
bottom color=black!20!white,
text centered,
text width=2.75cm,
minimum height = 1cm,
}
]
\node {Question}
child { node {Question}}
;
\end{tikzpicture}
\end{document}