Ryan's Blog

Including graphics in a LaTeX document

Posted in latex by ryanlayer on October 6, 2009

There are two ways to incorporate images into your LaTeX document, and both use the graphicx package by means of putting the command  \usepackage{graphicx} near the top of the LaTeX file, just after the documentclass command.

The two methods are

  1. include only PostScript images (esp. “Encapsulated PostScript”) if your goal is a PostScript document using dvips
  2. include only PDF, PNG, JPEG and GIF (Stefan correctly pointed out that GIF is not supported, you must convert to a supported fomat) images if your goal is a PDF document using pdflatex, TeXShop, or other PDF-oriented compiler.

In all cases, each image must be in an individual 1-image file; no animation files or multipage documents.

Only PostScript images

Most mathematical/scientific graphics software allows you to save graphics (figures, diagrams, graphs) in PostScript form; this includes Mathematica, Maple, Matlab, IDL, and xfig (a marvelous X figure-drawing program). Even bitmap images like JPEG and PNG files can be converted to PostScript form with programs like “xv” or “convert


Where you want a PostScript image to appear, use the \includegraphics command, possibly with scaling or rotation options, e.g.,


Of course, any of these can be inserted into a figure environment, and/or a centering environment or a framebox.

Then you must compile the document with latex followed by dvips -Ppdf, which produces a PostScript document with embedded PostScript images. You can convert the PostScript document to PDF using “ps2pdf” or “dvipdf”.

Two characteristics which the component (Encapsulated) PostScript image files must have are

  • no file contains more than one page
  • each has a valid BoundingBox line

If the PostScript file does not include a bounding box line, you can insert it using the text editor of your choice.

Only non-PostScript images

The compiler pdflatex (Unix) and TeXShop (Macintosh) convert LaTeX source directly to PDF, and do not accept PostScript images. Instead, they take PDF images, as well as bitmap pictures in PNG or JPEG or GIF format. So to use pdflatex, you must convert any PostScript images to one of these other forms. For photos, JPEG is best. For other bitmap images, PNG is best. For non-bitmap images (e.g., graphs, drawings, stuff with text and symbols) it is best to convert to PDF, using the command epstopdf (in the usual TeX bin directory, e.g., /usr/local/tex/bin/epstopdf). The command

unix>   epstopdf myfig.eps

produces the file myfig.pdf, which can then be used in the command \includegraphics{myfig.pdf}. for compilation with pdflatex or TeXShop.

The possible \includegraphics options with PDF/PNG/JPEG images are much the same as with PostScript, e.g.,


With PNG or JPEG you should specify an explicit width or height rather than “scale”, since bitmap images have no intrinsic size, nothing corresponding to Bounding Box information, although graphicx seems to use 72 pixels per inch as a default size for bitmap images.



2 Responses

Subscribe to comments with RSS.

  1. Stefan Kottwitz said, on October 7, 2009 at 9:18 pm

    Hi Ryan,

    you mentioned that GIF images would be supported, but as far as I know pdfTeX can natively handle just PDF, JPG, JBIG2, and PNG graphics formats.
    Did you ever test incorporating GIF files or did you see examples or pdftex/graphicx documentation regarding this matter?


    • ryanlayer said, on October 8, 2009 at 7:34 am

      Stefan, Good catch. GIF is not supported. I will change the post. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: