LaTeX/Importing Graphics

Importing external graphics
You can import external graphics using package . The most important command is . LaTeX itself treats the image like normal text, i.e. as a box of certain height and width.

The package documentation list the options  and , as well as others.

Using  several graphics formats are supported:,   and . Modern installations of LaTeX can use files as well, but indirectly.

LaTeX in -mode supports only -files.



You can align the images in a matrix. You just have to think of a proper width for the images.

Three images in one line, each image has a width of just 30 % of the available line width, centered with respect to the text below.



If you want to add a caption and let LaTeX keep track of the numbering, have a look at the floats section.

Converting graphics
You should also take a look at Export To Other Formats for other possibilities.
 * Note:

You can convert EPS to PDF with the epstopdf utility, included in package of the same name. This tool is actually called by pdflatex to convert EPS files to PDF in the background when the package is loaded. This process is completely invisible to the user.
 * epstopdf

You can batch convert files using the command-line. In Bourne Shell (Unix) this can be done by:

In Windows, multiple files can be converted by placing the following line in a batch file (a text file with a .bat extension) in the same directory as the images: which can then be run from the command line.

If produces a whole page with your small graphics somewhere on it, use or try using the ps2pdf utility which should be installed with Ghostscript (required for any TeX distribution). to crop the final PDF.

When all of the above fails, one can simplify the EPS file before attempting other conversions, by using the eps2eps tool (also see next section): This will convert all the fonts to pre-drawn images, which is sometimes desirable when submitting manuscripts for publication. However, on the downside, the fonts are NOT converted to lines, but instead to bitmaps, which reduces the quality of the fonts.
 * eps2eps

imgtops is a lightweight graphics utility for conversions between raster graphics (JPG, PNG, ...) and EPS/PS files.
 * imgtops

Inkscape can also convert files from and to several formats, either from the GUI or from the command-line. For instance, to obtain a PDF from a SVG image you can do: It is possible to run this from within a LaTeX file, the package (when running (pdf)latex with the --shell-escape option) can do this using Inkscape's pdf+tex export option, or a simple macro can be used. See [http://tex.stackexchange.com/q/2099/28808 How to include SVG diagrams in LaTeX? -- Stackexchange] See Export To Other Formats for more details.
 * Inkscape

To properly edit an EPS file, you can convert it to an editable format using pstoedit. For instance, to get an Xfig-editable file, do: And to get an SVG file (editable with any vector graphics tool like Inkscape) you can do: Sometimes pstoedit fails to create the target format (for example when the EPS file contains clipping information).
 * pstoedit

Under Windows, PDFCreator is an open source software that can create PDF as well as EPS files. It installs a virtual printer that can be accessed from other software having a "print..." entry in their menu (virtually any program).
 * PDFCreator


 * Raster graphics converters
 * Sam2p (convert) or
 * ImageMagick (convert) or
 * GraphicsMagick (gm convert).

These three programs operate much the same way, and can convert between most graphics formats. Sam2p however is the most recent of the three and seems to offer both the best quality and to result in the smallest files.

PNG alpha channel
Acrobat Reader sometimes has problems with displaying colors correctly if you include graphics in PNG format with alpha channel. You can solve this problem by dropping the alpha channel. On Linux it can be achieved with convert from the ImageMagick program:

Converting a color EPS to grayscale
Sometimes color EPS figures need to be converted to black-and-white or grayscale to meet publication requirements. This can be achieved with the eps2eps of the Ghostscript package and  programs:

Third-party graphics tools
We will not tackle the topic of procedural graphics created from within LaTeX code here (TikZ, PSTricks, MetaPost and friends). See Introducing Procedural Graphics for that.

You should prefer vector graphics over raster graphics for their quality. Raster graphics should only be used in case of photos. Diagrams of any sort should be vectors.

As we have seen before, LaTeX handles
 * EPS and PDF for vector graphics;
 * PNG and JPG for raster graphics.

If some tools cannot save in those formats, you may want to convert them before importing them.

Vector graphics
Dia is a cross platform diagramming utility which can export eps images, or generate tex drawn using the package.
 * Dia


 * Inkscape

Another program for creating vector graphics is Inkscape. It can run natively under Windows, Linux or Mac OS X (with X11). It works with Scalable Vector Graphics (SVG) files, although it can export to many formats that can be included in LaTeX files, such as EPS and PDF. From version 0.48, there is a combined PDF/EPS/PS+LaTeX output option, similar to that offered by Xfig. There are instructions on how to save your vector images in a PDF format understood by LaTeX and have LaTeX manage the text styles and sizes in the image automatically. . Today there is the which provides an  command to convert and include svg-graphics directly in your LaTeX document using Inkscape. You may have a look at this extended example too.

An extremely useful plug-in is textext, which can import LaTeX objects. This can be used for inserting mathematical notation or LaTeX fonts into graphics (which may then be imported into LaTeX documents).


 * Ipe

The Ipe extensible drawing editor is a free vector graphics editor for creating figures in PDF or EPS format. Unlike Xfig, Ipe represents LaTeX fonts in their correct size on the screen which makes it easier to place text labels at the right spot. Ipe also has various snapping modes (for example, snapping to points, lines, or intersections) that can be used for geometric constructions.

Yet another solution is provided by the packages, which allows TeX annotations to imported graphics. See Labels in the figures.
 * lpic

It is also possible to export vector graphics to EPS format using LibreOffice Draw, which is an open source office suite available for Windows, Linux and Mac.
 * LibreOffice

Vector editor TpX separates geometric objects from text objects. Geometric objects are saved into .PDF file, the rest is saved in .TpX file to be processed by LaTeX. User just create the graphics in TpX editor and calls the .TpX file from latex file by command  \input{...TpX}.
 * TpX

Xfig is a basic program that can produce vector graphics, which can be exported to LaTeX. It can be installed on Unix platforms.
 * Xfig

On Microsoft Windows systems, Xfig can only be installed using Cygwin-X; however, this will require a fast internet connection and about 2 gigabytes of space on your computer. With Cygwin, to run Xfig, you need to first start the "Start X - Server", then launch "xterm" to bring up a terminal. In this terminal type "xfig" (without the quotation marks) and press return.

Alternatively, WinFIG. WinFIG is an attempt to achieve the functionality of xfig on Windows computers.

There are many ways to use xfig to create graphics for LaTeX documents. One method is to export the drawing as a LaTeX document. This method, however, suffers from various drawbacks: lines can be drawn only at angles that are multiples of 30 and 45 degrees, lines with arrows can only be drawn at angles that are multiples of 45 degrees, several curves are not supported, etc.

Exporting a file as PDF/LaTeX or PS/LaTeX, on the other hand, offers a good deal more flexibility in drawing. Here's how it's done:   Create the drawing in xfig. Wherever you need LaTeX text, such as a mathematical formula, enter a LaTeX string in a textbox. <li> Use the Edit tool to open the properties of each of those textboxes, and change the option on the "Special Flag" field to Special. This tells LaTeX to interpret these textboxes when it opens the figure. <li> Go to File -> Export and export the file as PDF/LaTeX (both parts) or PS/LaTeX (both parts), depending on whether you are using pdflatex or pslatex to compile your file. <li> In your LaTeX document, where the picture should be, use the following, where "test" is replaced by the name of the image:

Observe that this is just like including a picture, except that rather than using <tt>\includegraphics</tt>, we use <tt>\input</tt>. If the export was into PS/LaTeX, the file extension to include would be .pstex_t instead of .pdf_t. <li> Make sure to include packages and  in the file, with the  command right below the  command, like this:

</ol> And you're done!

For more details on using xfig with LaTeX, this chapter of the xfig User Manual may prove helpful.

Commercial vector graphics software, such as Adobe Illustrator, CorelDRAW, and FreeHand are commonly used and can read and write EPS figures. However, these products are limited to Windows and Mac OS X platforms.
 * Other tools

Raster graphics
Photoshop can save to EPS.
 * Adobe Photoshop

GIMP, has a graphical user interface, and it is multi-platform. It can save to EPS and PDF.
 * GIMP

Plots and Charts
Generic Mapping Tools (GMT), maps and a wide range of highly customisable plots.
 * Generic Mapping Tools (GMT)

Gnumeric, spreadsheets has SVG, EPS, PDF export
 * Gnumeric

Gnuplot, producing scientific graphics since 1986. If you want to make mathematical plots, then Gnuplot can save in any format. You can get best results when used along PGF/TikZ.
 * Gnuplot

matplotlib, plotting library written in python, with PDF and EPS export. On the other hand there is a PGF export also. There are some tricks to be able to import formats other than EPS into your DVI document, but they're very complicated. On the other hand, converting any image to EPS is very simple, so it's not worth considering them.
 * matplotlib

R, statistical and scientific figures.
 * R

Editing EPS graphics
As described above, graphics content can be imported into LaTeX from outside programs as EPS files. But sometimes you want to edit or retouch these graphics files. An EPS file can be edited with any text editor since it is formatted as ASCII. In a text editor, you can achieve simple operations like replacing strings, changing the bounding box, or moving items slightly, but anything further becomes cumbersome. Vector graphics editors, like Inkscape, may also be able to import EPS files for subsequent editing. This approach also for easier editing. However, the importing process may occasionally modify the original EPS image.