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.
[Tex/LaTex] TikZ, node with multiple lines around
circlesnodestikz-pgf
Related Solutions
All TikZ node shapes are defined using lower-level PGF code. This is described in the pgfmanual
in section 75.5 Declaring New Shapes, on page 625 of the v2.1 manual.
You can use the existing code of the circle shape as a base and add the lines to it. The code can be found in the file ${TEXMF}/tex/generic/pgf/modules/pgfmoduleshapes.code.tex
.
Here the way I would do it:
Shape declaration:
\pgfdeclareshape{oplus}
%
% Shaped like '\oplus' math symbol. Based on 'circle' shape
%
{%
% All anchors are taken from the 'circle' shape:
\inheritsavedanchors[from={circle}]%
\inheritanchor[from={circle}]{center}%
\inheritanchor[from={circle}]{mid}%
\inheritanchor[from={circle}]{base}%
\inheritanchor[from={circle}]{north}%
\inheritanchor[from={circle}]{south}%
\inheritanchor[from={circle}]{west}%
\inheritanchor[from={circle}]{east}%
\inheritanchor[from={circle}]{mid west}%
\inheritanchor[from={circle}]{mid east}%
\inheritanchor[from={circle}]{base west}%
\inheritanchor[from={circle}]{base east}%
\inheritanchor[from={circle}]{north west}%
\inheritanchor[from={circle}]{south west}%
\inheritanchor[from={circle}]{north east}%
\inheritanchor[from={circle}]{south east}%
\inheritanchorborder[from={circle}]%
%
% Only the background path is different
%
\backgroundpath{%
% First the existing 'circle' code:
\pgfutil@tempdima=\radius%
\pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%
\pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%
\ifdim\pgf@xb<\pgf@yb%
\advance\pgfutil@tempdima by-\pgf@yb%
\else%
\advance\pgfutil@tempdima by-\pgf@xb%
\fi%
\pgfpathcircle{\centerpoint}{\pgfutil@tempdima}%
%
% Now the | and -- lines:
\pgfmoveto{\pgfpointadd{\centerpoint}{\pgfpoint{0pt}{\pgfutil@tempdima}}}%
\pgflineto{\pgfpointadd{\centerpoint}{\pgfpoint{0pt}{-\pgfutil@tempdima}}}%
\pgfmoveto{\pgfpointadd{\centerpoint}{\pgfpoint{\pgfutil@tempdima}{0pt}}}%
\pgflineto{\pgfpointadd{\centerpoint}{\pgfpoint{-\pgfutil@tempdima}{0pt}}}%
}%
}
Usage example:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfshape_oplus}
\begin{document}
\begin{tikzpicture}
\node [draw=blue,shape=oplus] {Test};
\end{tikzpicture}
\end{document}
Result:
You might also want to draw the additional lines in the \foregroundpath
instead. For this see the forbidden sign
shape in the file pgflibraryshapes.symbols.code.tex
is an good example.
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}
Best Answer
You can use the style more than once:
Or could nest them:
Code
Output