我正在尝试使用 TikZ 修改我为家谱编写的代码,方法是在姓名下方的一行中插入生日。这是初始代码,没有生日行,输出效果不错(如果有人知道如何在此处发布输出,请这样做并删除此括号请求):
\documentclass{article}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}
\usetikzlibrary{trees}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
[-,thick,
every node/.style={shape=rectangle,inner sep=3pt,draw,thick}]
\footnotesize
\node {Parent} [edge from parent fork down]
[sibling distance=2cm]
child {node {Child}
[sibling distance=2.2cm]
child {node {Grandchild 1}}
child {node {Grandchild 2}}
child {node {Grandchild 3}}
}
;
\end{tikzpicture}
\end{document}
我尝试使用以下代码在 和 之间添加一些带有生日的第二行\begin{document}
,\end{document}
但输出看起来很糟糕。连接线改变或消失或出现在错误的位置。(如果您可以发布以下代码的输出,请这样做并删除此括号请求。)
\begin{tikzpicture}
[-,thick,
every node/.style={shape=rectangle,inner sep=3pt,draw,thick}]
\footnotesize
\node {Parent} [edge from parent fork down]
[sibling distance=2cm]
child{node [name=block2, rectangle split, rectangle split parts=2]
{Child \nodepart{second}1/15/59}
[sibling distance=2.2cm]
child{node [name=block2, rectangle split, rectangle split parts=2]
{Grandchild 1\nodepart{second}10/20/80}}
child{node [name=block2, rectangle split, rectangle split parts=2]
{Grandchild 2\nodepart{second}2/5/84}}
child{node [name=block2, rectangle split, rectangle split parts=2]
{Grandchild 3\nodepart{second}8/9/89}}
}
;
\end{tikzpicture}
有人可以建议如何在不改变原始代码的树结构的情况下包含第二个生日行吗?
答案1
使用align=
键可以为日期添加换行符:
\documentclass{article}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}
\usetikzlibrary{trees}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
[-,thick,
every node/.style={shape=rectangle,inner sep=3pt,draw,thick,align=center}]
\footnotesize
\node {Parent\\ 1/15/59} [edge from parent fork down]
[sibling distance=2cm]
child {node {Child\\1/15/59}
[sibling distance=2.2cm]
child {node {Grandchild 1\\1/15/59}}
child {node {Grandchild 2\\1/15/59}}
child {node {Grandchild 3\\1/15/59}}
}
;
\end{tikzpicture}
\end{document}