7

I know how to draw different shapes using tikz, like this:

\documentclass{minimal}
\usepackage{tikz}
\begin{document}

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

\end{document}

enter image description here

However, I would like to put a number of different shapes together inside a node, and I couldn't yet find a simple way to do that. I will make a little figure to include in a large diagram which is already made of several nodes.

If this is not possible, or not easy, then how do I include a JPG or EPS file in a node?

Thank you!

8

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:

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

  • 2
    the pic feature was SO missing from previous versions...it makes so much sense...TikZ is awesome! – Bordaigorl Jul 23 '14 at 17:42
  • This is definitely what I needed! Thank you! – Jay Jul 23 '14 at 21:34
9

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

  • does this work for more detailed plots containing many unique points? – stars83clouds Nov 19 '17 at 20:54
  • @stars83clouds I think that you can put anything in the box. But I am not a TeXwizard... so I can be wrong. Try it and ask if something doesn't work. – Rmano Nov 19 '17 at 21:00
8

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.

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.