How do I use same figure multiple times?

The \includegraphics command offered by the graphics and graphicx packages already does this. Technically, the included image is placed only once in the resulting PDF and each additional instance just is a reference to the already embedded object.

Interestingly, this topic is not mentioned in the package documentation of these packages. (At least I was just not able to find it there). I learned it from the manual of the beamer class (§13 Graphics, page. 130), where Till Tantau writes about PGFs graphics commands:

Like \pgfdeclareimage, \includegraphics also includes an image only once in a .pdf file, even if it used several times (as a matter of fact, the graphics package is even a bit smarter about this than pgf)

However, ultimately this image folding feature depends on the graphics/graphicx backend driver, which is determined by the employed TeX/LaTeX engine: While it works out of the box with pdftex, xetex and luatex, images are included multiple times if going the dvips+ps2pdf route. For this case, user AlexG has suggested a workaround in another answer.


With pdfLaTeX, LuaLaTeX and XeLaTeX, repeat \inludegraphics{...} as often as desired. For these engines, the graphicx package already makes sure that a graphics file is included only once, and that references are inserted at other places.

For latex ->dvips->ps2pdf this is not done automatically and the final PDF will contain multiple instances of the same included file. This can be avoided by means of the xsavebox package:

\usepackage{graphicx}
\usepackage{xsavebox} %include content only once
...
\xsavebox{img for frequent use}{\includegraphics{example}}%
\xusebox{img for frequent use}
...
\xusebox{img for frequent use}

This method can still be applied to the other engines listed above, because it may reduce compilation time.

Tags:

Pdf

Graphics