使用 PGF/TikZ 的家谱或家谱

使用 PGF/TikZ 的家谱或家谱

由于 Stack Overflow 上有人建议我将其发布到这里,因此我会这样做:

我想用 LaTeX 绘制家谱。

我尝试使用 TikZ 来做到这一点,但由于你需要模拟人与人之间至少 3 种不同的关系(儿童、兄弟姐妹、夫妇),因此标准树模型似乎并不适合。

有没有一种简单的方法(也许是一个模板)来绘制家谱图?如果没有,那么构建自己的子包或其他东西的方法是什么?

后者的主要问题是元素的动态定位(取决于分支的数量)和前面提到的三个关系。

我编辑/扩展了这个问题,因此我更清楚地了解我到底想问什么:

给出了 TikZ/ 中的以下树\usetikzlibrary{trees}

family tree

创建方式:

\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\newcommand{\per}[1]{\parbox{2.5cm}{#1}}
\usetikzlibrary{trees}
\begin{document}

\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}
\end{document}

现在我有两个问题:

  1. 例如,我想为孩子和母亲添加一个兄弟姐妹。
  2. 我想分别添加父亲的母亲和父亲的父亲,

我该如何做呢?

答案1

我可以基于名为的新包提供新的答案genealogytree。在撰写本文时,所需的版本是0.90 (2015/05/22)。此包专门用于排版此类图表:

\documentclass{article}
\usepackage[all]{genealogytree}

\begin{document}

\begin{genealogypicture}[
  timeflow=left,               % time flows from right to left
  processing=tcolorbox,        % draw nodes with tcolorbox
  node size from=8mm to 3cm,   % height of nodes
  level size=2.8cm,            % width of nodes
  level distance=1cm,          % generation distance
                               % redefine default setting for female,male,neuter:
  tcbset={
    female/.style={colback=red!20,arc=1mm},
    male/.style={colback=blue!20,sharp corners},
    neuter/.style={colback=green!20,arc=0.5mm},
  },
  %
  box={colback=black,size=fbox,valign=center},    % node settings
  %
  edges={foreground={black,line width=0.25mm},    % edge settings
         background={white,line width=0.5mm}}
]

  %%%%%% the graph %%%%%%
  parent{
    g[neuter]{Child 1}
    c[neuter]{Child 2}
    parent{
      g[male]{Father}
      p[male]{Father's\\ father}
      p[female]{Father's\\ mother}
    }
    parent{
      g[female]{Mother}
      c[female]{Aunt}
      p[male]{Mother's\\ father}
      p[female]{Mother's\\ mother}
    }
  }
\end{genealogypicture}

\end{document}

enter image description here

答案2

在这种情况下,我不会使用该trees库,而是使用该库构建图表positioning;类似于以下的:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{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}

enter image description here

答案3

这看起来与 leyla akhmadeeva 和 boris veytsman 在 2008 年和 2009 年的 tug 会议上发表的论文中描述的医学谱系树相似,但很可能并不完全相同,这些论文随后发表在 tugboat 上:

家谱树不是用 tikz 构建的,而是用专门为此目的设计的包构建的。尽管如此,您可能会从这项工作中获得一些想法。

相关内容