Using encapsulated postscript graphics

Richard Kaye

22nd October 1999

1 Introduction

There are two standard graphics packages for L^{A}TEX, graphics and graphicx. My preference is for the graphicx package, and this is the one used in this document. However, all the features mentioned here are available from either package.

The graphicx package extends L^{A}TEX’s capabilities by allowing you to use other special features of the program you use to print dvi files (called the ‘driver’). A large number of drivers (printing programs, viewers, etc.) are catered for. With the right driver it is possible to incorporate bitmap images (in a wide variety of formats) into your document. In this department, we generally use the dvips driver, which converts a dvi file to postscript. Images can be incorporated easily if they are in encapsulated postscript (eps) format. This usually provides the quickest way to incorporated complex diagrams in a text. Also, if you use dvips, the graphics package provides other postscript commands to be used.

Before you use it you should be aware that, although some effort has been made to ensure the commands in the package work at other installations of L^{A}TEX, not all of them do, and some of them are quite specific to the particular driver, dvips. Therefore, it is not guarenteed that if you email a L^{A}TEX document prepared this way to a colleague elsewhere that you document will appear as you intend it when it is printed. In other words, incorporation of graphics might compromise one of the advantages of using L^{A}TEX—its portability.

There are many commands in the package. I will just mention the most commonly used ones here. For more information, see the documentation or ask me.

As always, you need to load the package:

\usepackage{graphicx}

or

\usepackage[dvips]{graphicx}

to specify the driver you intend to use (if this is not default on your system). You can include a picture as follows.

\begin{center}
\fbox{\includegraphics{ubhamlet.eps}}
\end{center}

This gives the following output.

Here, the \fbox produces the lines round the box, you do not need this if you don’t want it. The explicit centering is necessary.

There are two things to remember:

1. The \includegraphics command produces a ‘box’—like a character from an alphabet. You have to position it yourself.

2. For dvips, the graphics file to be read in (ubhamlet.eps) here should be an encpsulated postscript file. An ordinary postscript file doesn’t work. Most image tools can save their output as eps, and maple output and graphs can also be saved as eps.

The graphicx package provides commands to scale, rotate and reflect boxes.

\rotatebox{30}{Rotated} text.
Scaled figure: \scalebox{0.1}{\includegraphics{ubhamlet.eps}}

gives

Rotatedtext. Scaled figure:

where the rotation takes place about the box’s reference point (usually the bottom left corner), and the scaling changes the size—here to a tenth (0.1) of the original size. Also,

Scaled figure: \scalebox{0.2}[0.3]{\includegraphics{ubhamlet.eps}}

gives

Scaled figure:

The second optional argument to \scalebox is a separate scaling for the vertical dimension—here to 0.3 of the original vertical dimension.

There’s also a command to scale a figure to a given size. The following makes the figure exactly 1 inches wide:

Resized figure: \resizebox{1in}{!}{\includegraphics{ubhamlet.eps}}

gives

Resized figure:

A vertical dimension, e.g., 2in, can replace ‘!’, so

\resizebox{3in}{2in}{\includegraphics{ubhamlet.eps}}

would make the figure 3 inches wide and 2 inches high. The ‘!’ is used in place of the vertical dimension to ensure that the figure is rescaled by the same factor in both directions. If you wish, you can use ‘!’ for the horizontal dimension and specify the vertical one instead. You may also use \height, or \width to indicate the original height or width of the box, as in

\resizebox{1cm}{\height}{\includegraphics{ubhamlet.eps}}

which prints the box at its usual height but with a width of 1cm.

There are many other options for graphics in the graphicx package. The full documentation is in the file grfguide.tex, and can be obtained by running L^{A}TEX three times and then printing (with dvips!) as usual.

There are also many many other tricks that can be obtained using postscript. In all cases, please use them with care and taste!