# Reuse tikz picture in another tikz picture [duplicate]

I have a TikZ picture

\begin{tikzpicture}[scale=0.5]
\draw (-1,0) arc (180:360:1cm and 0.5cm);
\draw[dashed] (-1,0) arc (180:0:1cm and 0.5cm);
\draw (0,1) arc (90:270:0.5cm and 1cm);
\draw[dashed] (0,1) arc (90:-90:0.5cm and 1cm);
\draw (0,0) circle (1cm);
\end{tikzpicture}


which makes a small ball.

Is it possible to reuse this shape in another tikz picture?

I have another tikz picture in which I use

\draw[fill=yellow!30, fill opacity=0.5,text opacity=1] (B) circle (0.7cm) node[right] {$A$};


Instead of circle I want my small custom ball. How is that possible?

-

## marked as duplicate by Malipivo, Heiko Oberdiek, Guido, Andrew Swann, Claudio FiandrinoApr 13 '14 at 12:51

Are you using the latest version of TikZ (3.0)? If do, this has a new way of being done. –  Loop Space Apr 13 '14 at 11:32
I think this can be a duplicate of How can I draw a TikZ element multiple times against a shaded background? –  Claudio Fiandrino Apr 13 '14 at 11:40

Unrecommended way

There are several ways, this one puts tikzpicture environment to another tikzpicture environment with help of a \node.

%! *latex mal-tikz-tikz.tex
\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{tikz}
\begin{document}
\def\malpic{%
\begin{tikzpicture}[scale=0.5]
\draw (-1,0) arc (180:360:1cm and 0.5cm);
\draw[dashed] (-1,0) arc (180:0:1cm and 0.5cm);
\draw (0,1) arc (90:270:0.5cm and 1cm);
\draw[dashed] (0,1) arc (90:-90:0.5cm and 1cm);
\draw (0,0) circle (1cm);
\end{tikzpicture}%
}%End of \malpic...
\begin{tikzpicture}
\coordinate (B) at (0,0);
\node[fill=yellow!30, fill opacity=0.5,text opacity=1] at (B) {\malpic} node[right] {$A$};
\end{tikzpicture}
\end{document}


-
Embedding pictures inside pictures is generally not a great idea in TikZ. –  Loop Space Apr 13 '14 at 11:33
I agree with Andrew: this should not be encouraged. There are several alternatives, all listed in How can I draw a TikZ element multiple times against a shaded background? –  Claudio Fiandrino Apr 13 '14 at 11:39
I was quite happy when I found this solution in older versions of TikZ. It is fair enough when dealing with TikZ v3 where pic and external library have been introduced. I'm marking my answer as unrecommended. –  Malipivo Apr 13 '14 at 12:25
Have a look at this thread. I answered using a new scope with custom options for the embedding picture. The thread also covers the usage of the pic. Link –  moospit Apr 13 '14 at 12:41