How do I draw shapes inside a tikz node?

TiKZ 3.0 introduced pics. They are not exactly nodes but they allow to draw complex figures and manage them as a single one.

Search for them in TeX.SX and you'll find some more examples. Two of them:

  • Rotating pictures and labels together with pics in TikZ (this one also shows how to include a .pdf graphics into a node)
  • How to create something like a function (procedure, macros, etc.) in TikZ?

A simple example with your code.

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}[%
    complexnode/.pic={
\draw (0,0) ellipse (1 and 1.5)
      (0,2.5) circle (1)
      (2.5,0) circle (1.5);}]

\draw (0,0) pic {complexnode} (3,3) pic[blue, rotate=30] {complexnode};
\end{tikzpicture}

\end{document}

enter image description here


Another option is to use a LaTeX box --- never had problems with this (although you probably can't connect to "internal" objects). For simple cases it's quite easy:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,calc}

\begin{document}

\newsavebox{\genericfilt}
\savebox{\genericfilt}{%
    \begin{tikzpicture}[font=\small,
            >=stealth,
        ]
        \draw[thick, blue] (0,0) --(0.2,0) ..controls (0.5,1)..(1,1)..controls(1.2,1) and (1.8,0)..  
            node[black,left]{$H(f)$} (2,0) -- (2.5,0);
        \draw (0,0) node[below]{$0$} (1,0) node[below]{$f$} (2,0) node[below]{$\rightarrow\infty$};
    \end{tikzpicture}%
}

\begin{tikzpicture}
    \draw (0,0) node[draw](filt){\usebox{\genericfilt}};
    \draw [<-] (filt.west) -- ++(-0.5,0);
    \draw [->] (filt.east) -- ++(0.5,0);
\end{tikzpicture}

\end{document}

Example above


The quick answer: you can just nest a tikzpicture environment into the contents of your node:

\node[draw] (A) {
    \begin{tikzpicture}
      \draw (0,0) ellipse (1 and 1.5)
            (0,2.5) circle (1)
            (2.5,0) circle (1.5);
    \end{tikzpicture}};

However this is discouraged for various reasons but it will work for simple designs.

Another option is using the new pic feature of PGF 3.0.

To answer to the last question: you can simply put an \includegraphics command into your nodes.

Tags:

Nodes

Tikz Pgf