6

I'm trying to draw a "science" symbol in TikZ, represented by a stylized atom, and can't figure out how to do it. Is there any way to somehow define a magic TikZ style so I can do something like \node[science](C1) at (0,0){}; ?

I have tried using a \def macro and it can draw the symbol I want, but somehow the node name doesn't work in a way that I can refer to it later.

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\title{science symbol}
\begin{tikzpicture}[>=latex,
  font=\sffamily
]

\def\science#1#2 {
\node[circle, draw, minimum size=10mm] (#2) at #1 {};
\foreach \ang in {0,120,240}
  \draw[rotate around={\ang:#1}] #1 ellipse (4.5mm and 1.5mm);
\fill #1 circle (0.5mm);
}

\science{(0,0)}{C1};
\science{(2cm, 0)}{C2};
\draw[->] (C1) -- (C2);

\end{tikzpicture}
\end{document}

This draws what I want for the nodes

enter image description here

but I get an error on my \draw[->] (C1) -- (C2); statement:

Package pgf Error: No shape named C1 is known.
3
  • 1
    Try with \def\science#1#2{...} intead of \def\science#1#2 {...} (no space between #2 and {). Jan 23, 2017 at 5:37
  • @#$%#@%$#%$#@%$#% I like TeX except for its byzantine syntax.
    – Jason S
    Jan 23, 2017 at 15:37
  • You may use \newcommand\science[2]{...}. Jan 23, 2017 at 16:32

1 Answer 1

7

I muddled my way around using append after command, and got it to work:

\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, atom=5mm] (C2) at (2cm,0){};
\draw[->] (C1) -- (C2);

\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .