[Tex/LaTex] How to add multiple differently colored borders around a node

bordernodestikz-pgf

I want to draw a node to be filled with a table containing data, and it should have (three) differently colored adjacent borders around it. Couldn't find anything in the PGF manual, on the Net, nor on this forum, so I came up with this MWE…

Nesting three tikzpicture environments feels like a BIG amateuristic kludge to me, and if not, how do I get rid of the white space in between the borders?

\documentclass[pdftex,dutch]{article}
\usepackage{babel}
\usepackage{tikz}

\begin{document}

\definecolor{lichtgrijs}{RGB}{232,232,232}
\definecolor{DE.rood}{RGB}{222,0,0}
\definecolor{DE.geel}{RGB}{255,207,0}

\begin{tikzpicture}
\node[rectangle,line width=0.5mm,draw=black] at (0,0)
{\begin{tikzpicture}
 \node[rectangle,line width=0.5mm,draw=DE.rood] at (0,0)
 {\begin{tikzpicture}
  \node[rectangle,line width=0.5mm,draw=DE.geel,fill=lichtgrijs] at (0,0) {Vliegtuig};
  \end{tikzpicture}};
 \end{tikzpicture}};
\end{tikzpicture}

\end{document}

My kludge

Best Answer

Like this?

enter image description here

\documentclass[dutch]{article}
\usepackage{babel}
\usepackage{tikz}
\usetikzlibrary{fit}

\definecolor{lichtgrijs}{RGB}{232,232,232}
\definecolor{DE.rood}{RGB}{222,0,0} % Rood in Duitse vlag
\definecolor{DE.geel}{RGB}{255,207,0} % Geel in Duitse vlag

\begin{document}
    \begin{tikzpicture}[
box/.style = {draw=#1, line width=0.5mm,inner sep=0.25mm}
                        ]
\node (n1) [box=DE.geel,
            fill=lichtgrijs, inner sep=2mm] at (0,0) {Vliegtuig};
\node (n2) [box=DE.rood, fit=(n1)] {};
\node (n3) [box=black,   fit=(n2)] {};
    \end{tikzpicture}
\end{document}

Some Notes:

  • never nest tikzpicture in tikzpicture, which may raise unexpected side effects;
  • the fit library of tikz is used to get what you want;
  • you can define node style, which merges all nodes in one, but I'd like first to know whether the illustrated result is what you're looking for :-)

addendum: here is a three-color node variation. In particular, append after command= option in a node style is used for the middle and the outer colors:

\documentclass[dutch]{article}
\usepackage{babel}
\usepackage{tikz}
\usetikzlibrary{fit}

\definecolor{lichtgrijs}{RGB}{232,232,232}
\definecolor{DE.rood}{RGB}{222,0,0} % Rood in Duitse vlag
\definecolor{DE.geel}{RGB}{255,207,0} % Geel in Duitse vlag

\begin{document}

    \begin{tikzpicture}[
tcb/.style = {% three color border
              draw=DE.geel, fill=lichtgrijs,
              line width=0.5mm,inner sep=2mm,
              append after command={\pgfextra{\let\LN\tikzlastnode
                    \node [draw=DE.rood, line width=0.5mm,
                           inner sep=0.25mm,fit=(\LN)] {};
                    \node [draw, line width=0.5mm,
                           inner sep=0.75mm,fit=(\LN)] {};
              }}}
                        ]
\node (n1) [tcb] {Vliegtuig};
    \end{tikzpicture}
\end{document}

The result is the same as before.