PGF tools for working with external images:
use \pgfdeclareimage
to make your external image known to pgf/TikZ
use \pgfuseimage{name}
to include the image into your document
encapsulate the image by \pgfbox
to be able to use it within a node
An advantage of this way is that each image will be included just once in a pdf document and may be reused several times, thus saving space.
Follow general recommendations about including pictures: prefer vector format like pdf.
Code example:
This small example builds a tree with nodes using external images. I've simple taken images from our site for this.
\documentclass{article}
\usepackage{tikz}
\pgfdeclareimage{gold}{gold}
\pgfdeclareimage{silver}{silver}
\pgfdeclareimage{bronze}{bronze}
\begin{document}
\begin{tikzpicture}[sibling distance=12em]
\node {\pgfbox[center,bottom]{\pgfuseimage{gold}}}
child {node {\pgfbox[center,top]{\pgfuseimage{silver}}}}
child {node {\pgfbox[center,top]{\pgfuseimage{bronze}}}};
\end{tikzpicture}
\end{document}
Output:
Further explanation of the pgf commands:
\pgfdeclareimage[options]{image name}{file name}
declares an image without printing it. It understands key=value
options like height, width, page, interpolate and mask. The usual formats are supported and their extensions would automatically be tried.
\pgfuseimage{image name}
simply outputs that image.
\pgfbox[horizontal alignment,vertical alignment]{content}
outputs the content aligned left, center or right respectively top, center, bottom or base.
Detailed syntax, options and examples could be found in the pgf user guide.
The normal LaTeX approach:
You could simply use \includegraphics
, use it within \pgftext
. The example modified in this sense:
\documentclass{article}
\usepackage{tikz}
\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}[sibling distance=12em]
\node[anchor=south] {\pgftext{\includegraphics{gold}}}
child {node[anchor=north] {\pgftext{\includegraphics{silver}}}}
child {node[anchor=north] {\pgftext{\includegraphics{bronze}}}};
\end{tikzpicture}
\end{document}
Choosing the right way:
Using \includegraphics
instead of pgf commands is recommended here because \includegraphics
is a better implementation. The pgf way may be preferred if the document size matters and graphics are multiply used or if masking is desired.