Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to draw a circle node using tikz that has more than two lines around. I found this question: TikZ - multi-color double circle node with its very good accepted answer. Unfortunately, I have no idea how to extend it to more than two lines.

share|improve this question

2 Answers 2

up vote 7 down vote accepted

You can use the style more than once:

\node [draw, double circle={2pt}{black!75},
             double circle={4pt}{black!50},
             double circle={6pt}{black!25}] (c1) {};

Or could nest them:

\node [draw,
       double circle={2pt}{black!75,
         double circle={2pt}{black!50,
           double circle={2pt}{black!25}}}] (c1) {};

Code

\documentclass[tikz] {standalone}
\usetikzlibrary{calc}

\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{document}
\begin{tikzpicture}
\node [draw, double circle={2pt}{black!75},
             double circle={4pt}{black!50},
             double circle={6pt}{black!25}] (c1) {};
\node [draw, double circle={-2pt}{black!75},
             double circle={-4pt}{black!50},
             double circle={-6pt}{black!25}] (c2) at (2,0) {};
\end{tikzpicture}

\begin{tikzpicture}
\node [draw,
       double circle={2pt}{black!75,
         double circle={2pt}{black!50,
           double circle={2pt}{black!25}}}] (c1) {};
\node [draw,
       double circle={-2pt}{black!75,
         double circle={-2pt}{black!50,
           double circle={-2pt}{black!25}}}] (c2) at (2,0) {};
\end{tikzpicture}

Output

enter image description here

enter image description here

share|improve this answer
    
I think, that asks for a special shape that can deal with lists: radii={[black!75]2pt, [black!50]4pt, [black!25]6pt}. Hm … –  Qrrbrbirlbel Mar 3 '13 at 16:49

Sort of along the lines of what @Qrrbrbirlbel suggested. A hack which (temporarily) ignores the background path of the shape, and, in the behind-background path adds in a (somewhat crude) \foreach allowing multiple circle styles to be specified.

The outer sep specifies where arrows join the node, which does not have to be the outer most circle:

\documentclass{standalone}
\usepackage{tikz}
\makeatletter
\tikzset{
    circles/.code={%
        \tikzset{shape=circle}%
        % Ignore background path
        \let\pgf@sh@bg@circle=\relax%
        \def\pgf@sh@bbg@circle{%
            % \radius is defined *including* outser sep
            \pgfmathparse{\radius-max(\pgfkeysvalueof{/pgf/outer xsep},\pgfkeysvalueof{/pgf/outer ysep})}%
            \let\radius=\pgfmathresult% 
            \pgftransformshift{\centerpoint}%
            \foreach \opts/\r in {#1}%
                \path [every circle/.try]%
                    % Specified radii are in *addition* to minimum size.
                    \pgfextra{\expandafter\tikzset\expandafter{\opts}}%
                        circle [radius=\r+\radius];%
        }
    }%
}
\makeatother

\begin{document}

\begin{tikzpicture}[every circle/.style=draw]
    \node at (0,0) 
    [circles={black/0pt, black!75/2pt, black!50/4pt, black!25/6pt}] (A) {A};

    \node at (1.5, 0) 
    [every circle/.style=, 
        circles={{top color=black, bottom color=white}/12pt, 
        {top color=white, bottom color=black}/9pt,
        {top color=black, bottom color=white}/6pt,
        {top color=white, bottom color=black}/3pt,
        {top color=black, bottom color=white}/0pt},
        outer sep=6pt] (B) {B};

    \node at (3, 0) 
    [circles={{red, ultra thick}/0pt, {green, thick, dashed}/4pt, {blue, dotted}/8pt}] (C) {C};

    \draw [->](A) -- (B);
    \draw [->](B) -- (C);
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.