TikZ 中的简化家谱

TikZ 中的简化家谱

我正在尝试使用 TikZ 制作如下所示的简化家谱。

家谱

我知道家谱树包装和我怎样才能改进 TikZ 中的这棵家谱?,但这些树太复杂了,因为它们有名字并使用颜色。我正在寻找更简单的东西,比如上面的那个。

我怎样才能做到这一点?

答案1

我不知道你想如何使用它,但你总是可以用 Ti 定义一些样式然后您可以使用 Z 来创建不同的家谱。

这可能会帮助你入门(也许不是最优雅的方式):

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, shapes}

\tikzset{
    family tree/.style={
        every node/.style={
            inner sep=0pt
        },
        person/.style={
            minimum size=15pt,
            circle
        },
        woman/.style={
            person,
            draw
        },
        man/.style={
            person,
            label={[% 
                person,
                draw, 
                regular polygon, 
                regular polygon sides=3, 
                minimum size=20pt, 
                yshift=-2pt,
                label position=center
            ]},
        },
        level 2/.style={
            sibling distance=1cm
        },
        to sibling/.style={
            level distance=1.5cm,
            edge from parent path={
                let \p1 = ({$(\tikzparentnode.center)!.5!(\tikzchildnode.center)$} -| \tikzparentnode.center),
                    \p2 = (\tikzchildnode\tikzchildanchor),
                    \n1 = { veclen(\x1,\x2) }
                in
                    (\tikzparentnode\tikzparentanchor) --
                    ({$(\tikzparentnode.center)!.5!(\tikzchildnode.center)$} -| \tikzparentnode.center)
                    [rounded corners={(\n1 < 10 ? 0pt : 10pt)}]
                    -| 
                    (\tikzchildnode\tikzchildanchor)
            },
            shorten <=2pt
        },
        sibling/.style={
            level distance=.75cm,
            edge from parent path={
                let \p1 = (\tikzparentnode.center),
                    \p2 = (\tikzchildnode\tikzchildanchor),
                    \n1 = { veclen(\x1,\x2) }
                in
                    [rounded corners={(\n1 < 10 ? 0pt : 10pt)}]
                    (\tikzparentnode.center)
                    -| 
                    (\tikzchildnode\tikzchildanchor)
            }
        },
        marriage/.style={
            double, 
            double distance=2pt,
            shorten >=2pt,
            shorten <=2pt
        }
    }
}

\begin{document}

\begin{tikzpicture}[family tree]

\node (t1) at (-3,0) {} 
    child[sibling] { node[man] {} 
        child[to sibling] { node[woman] {} }
        child[to sibling] { node[man] {} }
    }
    child[sibling] { node[woman] {} 
        child[to sibling] { node[man] (n3) {} }
    }
    child[sibling] { node[woman] (n1) {} };
    
\node (t2) at (3,0) {} 
    child[sibling] { node[man] (n2) {} }
    child[sibling] { node[man] {} 
        child[to sibling] { node[woman] {} }
    }
    child[sibling] { node[woman] {} 
        child[to sibling] { node[man] {} }
    };
    
\node (t3) at ($(n1)!.5!(n2)$) {} 
    child[to sibling] { node[man] {} }
    child[to sibling] { node[woman] {} };

\node[right of=n3, woman] (n4) {};

\draw[marriage] (n1) -- (n2);

\draw[marriage] (n3) -- (n4);

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容