# Combined background gradient with custom centering

I am using the genealogytree package (based on tikz) to create a family tree. Code example can be found in this question. Basically, I have a simple tree of just me and my wife with imaginary baby, and then her tree is tilted 90 degrees to the one side and my tree is tilted 90 degrees to the other side. The best example code is in the first answer to the other question I linked.

Now I was looking at making the entire picture more pretty. In the manual to the genealogytree package, there is a first page with code included. In that example, the author uses a 25% opacity gradient from white to red to color the background behind the nodes. The gradient goes from one corner to the other. Example can be found here on page 1 and 2.

What I want to do is to take that gradient for each of us, put a blue color behind my own tree and a red color behind my wife's tree, and have the two gradients meet between us. Our personal nodes keep switching locations when I add more people to the tree at either side, so I would like to put the gradients covering the whole background of the page but always keeping the intersection centered between us.

## 1 Answer

In my answer, I use two shadings which meet at the center point of the core family. For this, an id=corefamily was added to the core family. The shading code is:

  \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}


The full code of the example is:

\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}

• Thank you. Curiously, my latex installation doesn't recognize "on background layer", although I am fairly certain I successfully compiled your example previously. Perhaps I did it on my linux box that time. On windows, it doesn't work. I did find a workaround though. \begin{document} \pgfdeclarelayer{background} \pgfsetlayers{background,main} ... \begin{pgfonlayer}{background} just replacing your {scope} with {pgfonlayer} does the trick. Since the tricky part was getting it centered on a piece, I will mark your answer as accepted. – GaRyu Dec 26 '15 at 23:58