[Tex/LaTex] TikZ – multi-color double circle node

circlesnodestikz-pgf

How do I draw a node with a double circle shape where one circle has a different color than the other circle?

multicolor node with doublecircle style

A single \node[whatever] {content} would be nice!

Best Answer

Here's a new style double circle that can be supplied to a node. It takes two arguments, one for specifying how much larger the radius of the outer circle is (default is 2pt), and the second for specifying the colour (or any combination of options, really) of the inner circle (default is blue).

If you specify a node name, this will refer to the outer node (thanks to Andrew Stacey for the suggestion).

\node (A) [double circle, draw=red] {b};
\node (B) at (2,0) [draw, double circle={-2pt}{orange}] {ABC};
\draw (A) -- (B);

will give you

\documentclass[border=4mm] {standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\tikzset{
    old inner xsep/.estore in=\oldinnerxsep,
    old inner ysep/.estore in=\oldinnerysep,
    double circle/.style 2 args={
        circle,
        old inner xsep=\pgfkeysvalueof{/pgf/inner xsep},
        old inner ysep=\pgfkeysvalueof{/pgf/inner ysep},
        /pgf/inner xsep=\oldinnerxsep+#1,
        /pgf/inner ysep=\oldinnerysep+#1,
        alias=sourcenode,
        append after command={
        let     \p1 = (sourcenode.center),
                \p2 = (sourcenode.east),
                \n1 = {\x2-\x1-#1-0.5*\pgflinewidth}
        in
            node [inner sep=0pt, draw, circle, minimum width=2*\n1,at=(\p1),#2] {}
        }
    },
    double circle/.default={2pt}{blue}
}


\begin{tikzpicture}
\node (A) [double circle, draw=red] {b};
\node (B) at (2,0) [draw, double circle={-2pt}{orange}] {ABC};
\draw (A) -- (B);
\end{tikzpicture}%
%
\end{document}