[Tex/LaTex] Tikz background color of node multilayer

tikz-pgf

I am trying to draw two nodes who are on a different layer. The background layer consists of the 'big' node and the foreground layer consist of the 'small' node.
Only the big node can have a background colour without affecting the background colour of the small one.
Below is an image that is produced by the MWE. the 'small' node and it's background should be white.

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{backgrounds,scopes}
\usetikzlibrary{arrows,positioning,shapes.geometric}

\begin{document}

\begin{tikzpicture}[remember picture]

    {[on background layer]
        \node (rect) at (4,2) [draw,thick,minimum width=2cm,minimum height=2cm, fill=red!30] {};
    }

    \node (smallRect) at (4,2) [draw,thick,minimum width=1cm, minimum height=1cm] {Small};

\end{tikzpicture}

\end{document}

I thought that the on background layer provided by the backgrounds TikZ library should work, but am I misunderstanding it?

Best Answer

I would not fill the smaller node white. This is because if you have something behind, it will be overpainted. Rather, I'd like to suggest to use even odd rule to spare the smaller node from being filled.

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{backgrounds,scopes}

\begin{document}

\begin{tikzpicture}[remember picture]

    \node (rect) at (4,2) [draw,thick,minimum width=2cm,minimum height=2cm] {};
    \node (smallRect) at (4,2) [draw,thick,minimum width=1cm, minimum height=1cm] {Small};
    {[on background layer]
    \fill[even odd rule,red!30] (rect.south west) rectangle (rect.north east)
    (smallRect.south west) rectangle (smallRect.north east); 
    }
\end{tikzpicture}
\end{document}

enter image description here