Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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)?

share|improve this question
2  
Some of your questions are answered in tex.stackexchange.com/questions/2099/… –  Caramdir Aug 21 '10 at 13:30
add comment

1 Answer 1

up vote 51 down vote accepted

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.

share|improve this answer
    
How do you know about pgfdecareimage? It is not to be found in pgfmanual.pdf. Can you answer in tex.stackexchange.com/questions/1900/… ? –  Łukasz Lew Aug 21 '10 at 14:30
    
Can I include PDF or SVG? –  Łukasz Lew Aug 21 '10 at 14:32
    
As far as I know PDF, JPEG, PNG, EPS and PS but not SVG. –  Stefan Kottwitz Aug 21 '10 at 14:40
2  
\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 Aug 21 '10 at 15:11
1  
I have posted a question about this: tex.stackexchange.com/questions/2163/… –  Martin Heller Aug 21 '10 at 21:15
show 10 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.