49

I would like to create a custom vector drawing in Inkscape and then use it many times in many tikz pictures.

Is it possible?
Should I use PDF or SVG or other output from Inkscape?
How to use external vector image in Tikz node?
How to define anchors / dimensions(bounding box)?

1

1 Answer 1

67

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:

tree with images as nodes

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.

15
  • How do you know about pgfdecareimage? It is not to be found in pgfmanual.pdf. Can you answer in tex.stackexchange.com/questions/1900/… ? Commented Aug 21, 2010 at 14:30
  • 1
    Can I include PDF or SVG? Commented Aug 21, 2010 at 14:32
  • 1
    As far as I know PDF, JPEG, PNG, EPS and PS but not SVG.
    – Stefan Kottwitz
    Commented Aug 21, 2010 at 14:40
  • 4
    \pgfdeclareimage is mentioned in the beamer manual: as Till Tantau wrote both pgf and beamer I guess he just assumed it was covered. I've added an answer to the other question about this.
    – Joseph Wright
    Commented Aug 21, 2010 at 15:11
  • 1
    I have posted a question about this: tex.stackexchange.com/questions/2163/… Commented Aug 21, 2010 at 21:15

You must log in to answer this question.

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