5

I want the atom symbol color and style below to be the same as the enclosing node style; how do I do it? Is there a way to reference the linestyle of \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}

enter image description here

3

I muddled my own way through this again, and found an alternative approach using \pgfdeclareshape rather than append after command. (why does it always feel like a painful victory when I do this sort of thing???) Other reference questions I used were

but it was basically just how to use \pgfdeclareshape to work from the circle shape, see https://svn.ssec.wisc.edu/repos/geoffc/LaTeX/beamerposter_UW-SSEC/pgfmoduleshapes.code.tex for source code.

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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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