TikZ,周围有多条线的节点

TikZ,周围有多条线的节点

我想使用 tikz 绘制一个周围有两条以上线条的圆形节点。我发现了这个问题:TikZ-多色双圆节点答案非常好,已被接受。不幸的是,我不知道如何将其扩展到两行以上。

答案1

您可以多次使用该样式:

\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={2pt}{black!50,
           double circle={2pt}{black!25}}}] (c1) {};

代码

\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}

输出

在此处输入图片描述

在此处输入图片描述

答案2

有点像@Qrrbrbirlbel建议的那样。一个 hack 会(暂时)忽略形状的背景路径,并在背景路径中添加(有点粗糙的)\foreach允许指定多个圆形样式。

指定outer sep箭头连接节点的位置,不一定是最外面的圆:

\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}

在此处输入图片描述

相关内容