# pgf/tikz: Making the filling / gap between double border lines transparent

I have a rectangular box with double border lines. The pgf manual (chapter 15.3.5 Graphic Parameters: Double Lines and Bordered Lines) says that the default filling is white. I want the gap to be transparent so that you can see the background color.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds,fit}
\begin{document}

\begin{tikzpicture}
\node (myNode1) at (0,0) [
rectangle,
draw,
double,
double distance=1mm
] {Double};
%
\node (myNode2) at (0,-10mm) [
rectangle,
draw,
double=red,
double distance=1mm
] {Double};
%
\begin{pgfonlayer}{background}
\node [fill=black!30,fit=(myNode1) (myNode2)] {};
\end{pgfonlayer}
\end{tikzpicture}

\end{document}


Any ideas?

EDIT: I do not want to give the gap manually the same color as the background since I want to be the background "anything" like a picture or something that is not of control of tikz.

-
Does double=none do what you want? –  Peter Grill Feb 8 at 17:52
Hello Peter. Sadly it does not seem to help. –  Manuel Kuehner Feb 8 at 18:34
Instead of double lines you can use one of the answers to tikz-how-to-create-a-new-shape-type-comment –  Ignasi Feb 9 at 19:55

Easiest is to give the same color to double as that of the background:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds,fit}
\begin{document}

\begin{tikzpicture}
\node (myNode1) at (0,0) [
rectangle,
draw,
double,
double distance=1mm
] {Double};
%
\node (myNode2) at (0,-10mm) [
rectangle,
draw,
double=black!30,
double distance=1mm,
fill=green!30
] {Double};
%
\begin{pgfonlayer}{background}
\node [fill=black!30,fit=(myNode1) (myNode2)] {};
\end{pgfonlayer}
\end{tikzpicture}

\end{document}


If you aren't happy with this, then you have to hack into the inner code as there is no relevant key involved. You may also define a new command.

-
This isn't an answer but too long for a comment. –  Harish Kumar Feb 8 at 16:53
Hello Harish. That's what I did as a workaround of course. I was hoping that there is a more general solution where the background can be "anything". –  Manuel Kuehner Feb 8 at 18:35
@ManuelKuehner More general solution needs some deep hack, I am afraid. –  Harish Kumar Feb 8 at 22:43
I accept the workaround since there is no real solution :(. –  Manuel Kuehner Feb 9 at 12:20

Two more options where you don't need to worry about background color.

The first one (doubleA in code below) uses a matrix node. A matrix node is a node with some other nodes inside. Therefore, if matrix node is only drawn and not filled, it keeps its transparency. Be careful with this option because your internal node must finish with \\.

The second ont (doubleB) uses append after command option to draw a surrounding node with fitting library. Like with doubleA this outer node has no background if you dont fill it.

You can select double line separation adjusting inner sep for matrix or fit nodes. If you need to make further reference to this nodes you will need to select between outer or inner one. With matrix solution you fix outer node name and inner one will be name-1-1, while with fit solution, you fix inner node name and outer one is called name-b (you can change this name).

\documentclass[tikz,border=3mm]{standalone}

\usetikzlibrary{backgrounds,fit,matrix}
\begin{document}

\tikzset{doubleA/.style = {matrix of nodes,
draw, inner sep=1mm,
nodes = {rectangle, draw, inner sep=.3333em}}}

\tikzset{doubleB/.style = {rectangle, draw,
append after command={
\pgfextra{\node[fit=(\tikzlastnode), draw] (\tikzlastnode-b) {};}
}}}

\begin{tikzpicture}

\node[doubleA] at (0,0) (A) {Double\\};

\node[doubleB] at (0,-1)  (B) {Double};

\begin{pgfonlayer}{background}
\node [fill=black!30,fit={(A) (B-b)}] {};
\end{pgfonlayer}
\end{tikzpicture}

\end{document}


Update

Another example which shows how to place or connect this kind of nodes. Every node is double, it's made with inner and outer nodes, therefore you can connect inner or outer nodes with any other one. You can also use inner or outer nodes to anchor them.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{backgrounds,fit,matrix,positioning}
\begin{document}

\tikzset{doubleA/.style = {matrix of nodes,
draw, inner sep=1mm,
nodes = {rectangle, draw, inner sep=.3333em}}}

\tikzset{doubleB/.style = {rectangle, draw,
append after command={
\pgfextra{\node[fit=(\tikzlastnode), draw] (\tikzlastnode-b) {};}
}}}

\begin{tikzpicture}

\fill[red!20] (-1,-1) rectangle (4,4);
\draw[help lines] (-1,-1) grid (4,4);

\node[doubleA] (A)  at (0,0) {DoubleA\\};

\node[doubleB, anchor=south west] at (2,1)  (B) {DoubleB};

\node[doubleA, matrix anchor=south west] at (1,3)  (C) {DoubleA\\};

\node[doubleA, matrix anchor=D-1-1.south west, above=2cm of A.center] (D) {DoubleA\\};

\draw [<->] (A) to [out=80, in=260] (D);
\draw [<->] (D-1-1.north) |-(C-1-1);
\draw [<->] (A-1-1) to [out=10, in=180] (B-b);
\draw [<->] (A) to [out=-10, in=-80] (B);
\end{tikzpicture}
\end{document}


-
Thx. In real I need this stuff to draw block diagrams (with right of...). I have to check if your idea still works when I connect the blocks and so on. Again - Thx. –  Manuel Kuehner Mar 21 at 13:15
@ManuelKuehner: I've added some examples showing how to place and connect this kind of nodes. –  Ignasi Jun 2 at 10:12
Thanks a lot - looks great! –  Manuel Kuehner Jun 2 at 13:26