结合背景渐变和自定义居中

结合背景渐变和自定义居中

我正在使用 genealogytree 包(基于 tikz)来创建家谱。代码示例可以在这里找到在这个问题中基本上,我有一个简单的树,只有我和我的妻子以及想象中的婴儿,然后她的树向一侧倾斜 90 度,我的树向另一侧倾斜 90 度。最好的示例代码在我链接的另一个问题的第一个答案中。

现在我想让整个画面更漂亮。在 genealogytree 包的手册中,第一页包含代码。在该示例中,作者使用从白色到红色的 25% 不透明度渐变来为节点后面的背景着色。渐变从一个角到另一个角。示例可在此处找到在第 1 页和第 2 页。

我想要做的是为我们每个人取一个渐变色,在我自己树后面放一个蓝色,在我妻子树后面放一个红色,然后让两个渐变色在我们之间相交。当我在树的两边添加更多人时,我们的个人节点会不断切换位置,所以我想让渐变覆盖整个页面的背景,但始终保持交点在我们之间的中心。

答案1

在我的回答中,我使用了两个在核心系列中心点相交的阴影。为此,id=corefamily向核心系列添加了一个。阴影代码为:

  \begin{scope}[on background layer]
    \path([xshift=-2mm,yshift=-2mm]current bounding box.south west)
        rectangle ([xshift=2mm,yshift=2mm]current bounding box.north east);
    \path[left color=blue!75,right color=blue!50!red!75]
      (current bounding box.south west) rectangle (corefamily|-current bounding box.north east);
    \path[left color=blue!50!red!75,right color=red!75]
      (corefamily|-current bounding box.south west) rectangle (current bounding box.north east);
  \end{scope}

在此处输入图片描述

示例的完整代码为:

\documentclass[9pt]{report}
\usepackage[a3paper,landscape,layoutoffset={0pt,0pt},hscale=0.85, vscale=0.9, inner=5mm, top=20mm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
%\usepackage[swedish]{babel}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage[space]{grffile}
\usepackage{xcolor}
\usepackage{epstopdf}
\usepackage[all]{genealogytree}
\usetikzlibrary{backgrounds}

\begin{document}

    \tcbset{male/.style={colframe=black, colback=blue!06, watermark text=\gtrSymbolsSetDraw{blue!16}\gtrsymMale}}
    \tcbset{female/.style={colframe=black, colback=red!07, watermark text=\gtrSymbolsSetDraw{red!17}\gtrsymFemale}}

    \gtrset{
            box={colback=white},
            edges={swing,no background,foreground=black!50},
            }


\begin{tikzpicture}
        \genealogytree[timeflow=down,
        %tree offset=0.4 cm,
        level size=3 cm,
        node  size=5 cm,
        level distance=1.25 cm,
        child distance=1.75 cm,
        parent distance=2.5 cm,
        further distance = 3 cm
        ]
        {
            sandclock[id=corefamily]
            {
                parent
                {
                    g[male, id=DEL2]{Dan-Erik Sigurd Lindberg}
                }
                parent
                {
                    g[female, id=AKL2]{Angsana Keeratijarut Lindberg}
                }
                c[male]{test}
            }
        }

        \genealogytree[timeflow=right, set position=DEL at DEL2,
            box={colback=white},
            edges={swing,no background,foreground=black!50},
            level size=5 cm,
            node  size=3 cm,
            level distance=1.75 cm,
            child distance=1.25 cm,
            parent distance=0.1 cm,
            further distance = 3 cm
        ]
        {
            sandclock
            {
                child
                {
                    g[male]{Olle Lars Olof Evert Lindberg}
                }
                child
                {
                    g[male]{Holger Nils Ã…ke Lindberg}
                }
                child
                {
                    g[female]{Hedvig Emma-Lena Liljenberg}
                }
                child
                {
                    g[male, pivot, id=DEL]{Dan-Erik Sigurd Lindberg}
                }
                parent
                {
                    c[female]{Kerstin Eriksson}
                    c[male]{Bengt Nilsson}
                    g[female, pivot]{Ingrid Birgitta Lindberg}
                    parent
                    {
                        g[male, pivot]{Axel Nilsson}
                    }
                    parent
                    {
                        g[female, pivot]{Anna Nilsson}
                        parent
                        {
                            g[male, pivot]{Lars Petter Hansander}
                        }
                        parent
                        {
                            g[female, pivot]{Emma Katarina Lindén}
                        }
                    }
                }
                parent
                {
                    g[male, pivot]{Rolf Sigurd Lindberg}
                    c[female]{Margareta Eman}
                    c[female]{Monica Björklund}
                    parent
                    {
                        g[male, pivot]{Curt Sigurd Lindberg}
                        parent
                        {
                            g[male, pivot]{Sigurd Lindberg}
                        }
                        parent
                        {
                            g[female]{Elin Lindberg}
                        }
                    }
                    parent
                    {
                        g[female]{Hedvig Lindberg}
                    }
                }
            }
        }

        \genealogytree[timeflow=left, set position=AKL at AKL2,
            box={colback=white},
            edges={swing,no background,foreground=black!50},
            level size=5 cm,
            node  size=3 cm,
            level distance=1.75 cm,
            child distance=1.25 cm,
            parent distance=0.1 cm,
            further distance = 3 cm
            ]
        {
            sandclock
            {
                child
                {
                    g[male]{Attachai Keeratijarut}
                }
                child
                {
                    g[female, pivot, id=AKL]{Angsana Keeratijarut Lindberg}
                }
                parent
                {
                    g[male, pivot]{Anop Keeratijarut}
                }
                parent
                {
                    g[female, pivot]{Renu Keeratijarut}
                }
            }
        }

  \begin{scope}[on background layer]
    \path([xshift=-2mm,yshift=-2mm]current bounding box.south west)
        rectangle ([xshift=2mm,yshift=2mm]current bounding box.north east);
    \path[left color=blue!75,right color=blue!50!red!75]
      (current bounding box.south west) rectangle (corefamily|-current bounding box.north east);
    \path[left color=blue!50!red!75,right color=red!75]
      (corefamily|-current bounding box.south west) rectangle (current bounding box.north east);
  \end{scope}

\end{tikzpicture}


\end{document}

相关内容