在命令后附加中使用 \tikzlastnode 的线型和颜色

在命令后附加中使用 \tikzlastnode 的线型和颜色

我希望下面的原子符号颜色和样式与封闭节点样式相同;我该怎么做?有没有办法引用的线条样式\tikzlastnode

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, calc}
\begin{document}
\title{science symbol}
\begin{tikzpicture}[>=latex,
  font=\sffamily,
  atom/.style = {circle, minimum size=#1,
    append after command={%
      \pgfextra{ 
        \foreach \ang in {0,120,240}
        \draw[rotate around={\ang:(0,0)}] (\tikzlastnode.center) ellipse (0.45*#1 and 0.15*#1); 
        \fill (\tikzlastnode.center) circle (0.05*#1);
      }
    }
  }
]

\node[draw, atom=10mm] (C1) at (0,0){};
\node[draw, very thin, red, atom=10mm] (C2) at (2cm,0){};
\node[draw, thick, green, atom=10mm] (C3) at (2cm,2cm){};
\draw[->] (C1) -- (C2);
\draw[->] (C1) -- (C3);

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

我又摸索着解决了这个问题,并找到了一种替代方法,使用\pgfdeclareshape而不是append after command。(为什么当我做这种事时,总感觉像是一次痛苦的胜利???)我使用的其他参考问题是

但它基本上只是如何使用形状\pgfdeclareshape来工作circle,看看https://svn.ssec.wisc.edu/repos/geoffc/LaTeX/beamerposter_UW-SSEC/pgfmoduleshapes.code.tex源代码。

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, calc}
\begin{document}
\title{science symbol}
\pgfdeclareshape{atomshape}{%
  \inheritsavedanchors[from=circle]%
  \inheritanchorborder[from=circle]%
  \inheritanchor[from=circle]{center}%
  %
  \backgroundpath{%
    \pgfpathcircle{\pgfpointorigin}{0.1*\radius}
    \pgfusepath{fill}
    \pgfpathcircle{\pgfpointorigin}{\radius}%
    \foreach\ang in {0,120,240}{
      \pgftransformrotate{\ang}
      \pgfpathellipse{\pgfpointorigin} 
                 {\pgfpoint{0.9*\radius}{0cm}} 
                 {\pgfpoint{0cm}{0.3*\radius}}
    }
  }%
}
\begin{tikzpicture}[>=latex,
  font=\sffamily,
  atom/.style = {atomshape, minimum size=#1}
]

\node[draw, atom=10mm] (C1) at (0,0){};
\node[draw, very thin, red, atom=10mm] (C2) at (2cm,0){};
\node[draw, thick, green, atom=10mm] (C3) at (2cm,2cm){};
\draw[->] (C1) -- (C2);
\draw[->] (C1) -- (C3);

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容