![使用 LaTeX 绘制家谱图](https://linux22.com/image/258326/%E4%BD%BF%E7%94%A8%20LaTeX%20%E7%BB%98%E5%88%B6%E5%AE%B6%E8%B0%B1%E5%9B%BE%20.png)
可能重复:
使用 PGF/TikZ 的家谱或家谱
我想用 LaTeX 绘制家谱。
我尝试使用 tikz 来做到这一点,但由于你需要模拟人与人之间至少 3 种不同的关系(儿童、兄弟姐妹、夫妇),标准树模型似乎并不适合。
有没有一种简单的方法(也许是一个模板)来绘制家谱图?如果没有,那么构建自己的子包或其他东西的方法是什么?
主要问题是元素的动态定位(取决于分支的数量)和前面提到的三种关系。
编辑:
我编辑了这个问题,以便更清楚地了解我到底想问什么:
给出了 tikz / usetikzlibrary{trees} 中的以下树:
创建方式:
\newcommand{\per}[1]{\parbox{2.5cm}{#1}}
\tikzstyle{female} = [rectangle, draw, fill=red!20, rounded corners, minimum height=3em]
\tikzstyle{male} = [rectangle, draw, fill=blue!20, minimum height=3em]
\tikzstyle{neutral} = [rectangle, draw, fill=green!20, minimum height=3em]
\begin{tikzpicture}[level distance=4cm]
\node[neutral] {\per{Child}}
[edge from parent fork right,grow=right]
child {
node[female] {\per{Mother}}
child {
node[female] {\per{Mother's mother}}
}
child {
node[male] {\per{Mother's father}}
}
}
child {
node[male] {\per{Father}}
};
\end{tikzpicture}
现在我有两个问题:
- 例如,我想为孩子和母亲添加一个兄弟姐妹。
- 我想添加父亲的母亲和父亲的父亲。
我该如何做呢?
答案1
在这种情况下,我不会使用树;这里有一个选择:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{trees,positioning}
\begin{document}
\tikzset{
every node/.style={rectangle,draw,minimum height=3em,text width=2.5cm},
female/.style = {fill=red!20, rounded corners},
male/.style = {fill=blue!20},
neutral/.style = {fill=green!20}
}
\begin{tikzpicture}[node distance=8pt and 33pt]
% the nodes
\node[neutral] (chi1) {Child 1};
\node[neutral,below= of chi1] (chi2) {Child 2};
\node[male,above right=of chi1] (father) {Father};
\node[female,below right=of chi2] (mother) {Mother};
\node[female,below =of mother] (aunt) {Aunt};
\node[male,above right=of father] (ffather) {Father's\\ father};
\node[female,below right=of father] (fmother) {Father's\\ mother};
\node[male,above right=of mother] (mfather) {Mother's\\ father};
\node[female,below right=of aunt] (mmother) {Mother's\\ mother};
% some auxiliary coordinates for the edges
\coordinate[right=15pt of chi1] (auxc1);
\coordinate[right=15pt of chi2] (auxc2);
\coordinate[right=15pt of father] (auxf);
\coordinate[right=15pt of mother] (auxm);
\coordinate[right=15pt of aunt] (auxa);
% the edges
\draw (father.west) -| (auxc1) |- (mother.west);
\draw (chi1) -- (auxc1);
\draw (chi2) -- (auxc2);
\draw (ffather.west) -| (auxf) |- (fmother.west);
\draw (father) -- (auxf);
\draw (mfather.west) -| (auxm) |- (mmother.west);
\draw (mother) -- (auxm);
\draw (aunt) -- (auxa);
\end{tikzpicture}
\end{document}
答案2
您可以尝试“pstricks”中的“pst-tree”包:
http://tug.org/PSTricks/main.cgi?file=pst-tree/pst-tree
它有自己的语法,但是通过例子你可以很快学会它。