Wednesday, February 18, 2009

Including Images in LaTeX Documents

Following are a few notes on including graphics (images) into Latex documents.

I recommend using the graphicx package. There is another one called graphcis that has the same functionality, but uses a different syntax. In my opinion, graphicx has the better syntax.
Common options are:
  • Driver name, such as dvips, dvipdf, and pdftex.
  • draft: draw an empty box in place of the image.
When compiling with latex or texify to create a DVI file (and then to PS or PDF using dvips, dvipdfm, or ps2pdf if needed) you can include EPS files using the command
  \includegraphics[key=value, ...]{fileName}
Common key/values are
  • scale= number
  • width= length
  • height= length
  • totalheight= length : height plus depth; generally used when rotating the graphic
  • keepaspectratio= boolean : true or false
  • angle= number : the angle to rotate the image counterclockwise, in degrees
  • origin= location : the anchor point for rotation; legal values include c (center), t (top), r (right), bl (bottom-left), B (baseline), and certain combinations, such as tr
  • draft= boolean : true or false; draw an empty box in place of the image.
  • bb= llx lly urx ury : creates a new bounding box using the specified coordinates; default unit is bp (points)
  • clip= boolean : true or false; don't draw parts of the graphic outside the bounding box
  • viewport= llx lly urx ury : creates a bounding box relative to origin (generally ll) of the existing one
  • trim= left bottom right top : creates a new bounding box by adding or removing the given lengths to each side of the existing bounding box
You can convert images to EPS files using the convert command in the ImageMagick tool suite. Other tools such as matlab, and PaintShop Pro (maybe Gimp?) also let you save images as EPS files.

When using pdflatex to create PDF files you can use the same commands above, but instead of including EPS files, you can include PNGs, BMPs, and GIFs directly (no need to convert to EPS files first):
  1. CTAN, CTAN graphicx package information, 2009
  2. D.P. Carlisle, Packages in the graphics bundle, (graphics guide for Latex3, PDF), 2005
  3. Including graphics in a LaTeX document,, 2008