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.

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!

share|improve this question
1  
Welcome to TeX.sx! What exactly do you mean by "double circle shape"? Can you show a picture, perhaps? –  Torbjørn T. Dec 1 '11 at 23:01
    
thanks! could you re-edit to make the picture inline? i can't do it since i've <10 reputation –  brillout.com Dec 1 '11 at 23:30
2  
Done. You can use backticks (`) to mark inline code, as I did in my edit. Or, select the code and hit Ctrl + K. –  Torbjørn T. Dec 1 '11 at 23:33
add comment

3 Answers

up vote 21 down vote accepted

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}
share|improve this answer
    
I would make the outer circle the one drawn by the node (at least by default) and increase the inner sep to ensure that there is room for the inner circle. My reason for this is that with a double circle I would expect the node boundary to be on the outer circle, not the inner one. –  Loop Space Dec 2 '11 at 7:45
    
@AndrewStacey: The first argument can be negative though. So depending on the input which circle is the outer one may vary. I do agree that by default a positive value should give the expected behaviour, which I would also expect to be the outer circle as the node boundary. –  Roelof Spijker Dec 2 '11 at 8:10
    
@wh1t3 Yes, I see that. My comment is all about polishing and nothing about substance. It's a nice solution (particularly as it doesn't involve defining a new node shape) and this is purely about what a user might expect the default action to be. –  Loop Space Dec 2 '11 at 8:23
    
@AndrewStacey: Good point! Unfortunately, the value of inner sep can't simply be accessed using \pgfkeysvalueof{/tikz/inner sep}, so making this solution behave as you suggest isn't trivial. Feel free to edit this answer or add a new one if you come up with a way to make the outer circle the node border. –  Jake Dec 2 '11 at 12:30
    
Looking at the code, it should be the value of /pgf/inner xsep (and /pgf/inner ysep). I haven't tested it, though. –  Loop Space Dec 2 '11 at 13:07
add comment

Not sure exactly what you want, but here are five different ways:

enter image description here

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% Version 1
\draw [red ] (0,0) circle (5pt);
\draw [blue] (0,0) circle (10pt);
\node at     (0,0) {1};

% Version 2
\node [draw=blue,double=red, circle, inner sep=1pt] at (1,0) {2};

% Version 3
\draw [draw=red, inner sep=1pt]  (2,0) circle (8pt);
\node [draw=blue, circle, inner sep=1pt] at (2,0) {3};

% Version 4
\path (3,0) node [draw=red,shape=circle]  {}
      (3,0) node [draw=blue,shape=circle] {4};

% Version 5 (similar to Version 2)
\path (4,0) node [draw=blue, shape=circle, double=red] {5};
\end{tikzpicture}
\end{document}
share|improve this answer
    
If not, replace draw commands with \fill [blue] (0,0) circle (10pt);\fill [red ] (0,0) circle (5pt);. –  percusse Dec 1 '11 at 23:13
    
thanks! is there a way to have a single \node[whatever] {content}? –  brillout.com Dec 1 '11 at 23:27
    
See updated solution. Is Version 2 or 5 what you want? –  Peter Grill Dec 1 '11 at 23:36
    
i would like the stroke to have a different color and both circle having slightly different size, so version 3 would be the closest one. thanks for all the nice tikz snippets –  brillout.com Dec 1 '11 at 23:47
add comment

great job, I used your code to start a vertical timeline..

\usetikzlibrary[calc,arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri,shapes,mindmap,shadows]

\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.8*\pgflinewidth}
        in
            node [inner sep=0.01pt, draw,circle, fill, minimum width=1*\n1,at=(\p1),#2] {}
        }
    },
    double circle/.default={2.5pt}{blue!50}
}
\begin{tikzpicture}[
nonterminal/.style={rectangle,minimum size=6mm,very thick,draw=red!50!black!50,top color=white, bottom color=red!50!black!20,font=\itshape},
%{ The shape:, The size:, The border:, 50 % red and 50% black, and that mixed with 50% white,  The filling:, a shading that is white at the top...,and something else at the bottom, Font}
terminal/.style={rectangle,minimum size=6mm,rounded corners=3mm,very thick,draw=black!50,top color=white,bottom color=black!20,font=\ttfamily},
line width=4pt,
circulo/.style={circle,minimum size=3mm,line cap=rect,draw=blue!50,top color=white,bottom color=blue!40,font=\ttfamily}
]
\node (A) [double circle, draw=blue!20] {};
\node (B) [double circle, draw=blue!20][below=of A] {};
\node (C) [double circle, draw=blue!20][below=of B] {};
\node (D) [double circle, draw=blue!20][below=of C] {};
\node (E) [double circle, draw=blue!20][below=of D] {};
\node (F) [double circle, draw=blue!20][below=of E] {};
\node (G) [double circle, draw=blue!20][below=of F] {};
\node (H) [double circle, draw=blue!20][below=of G] {};
\draw[-] [blue!20] (A) -- (H);
\node (B1) [rectangle, minimum size = 6mm][below=of A,label=right:Primeira Etapa, label=left:2008] {};

\end{tikzpicture}
share|improve this answer
6  
Note that this is a Question and Answer (or Q&A) site and not a forum that hosts discussions on a specific topic. Even though this is a neat application of an answer for the given question, it is technically not an "answer". –  Werner Feb 7 '12 at 18:48
add comment

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.