Docsity

Using Imported Graphics in LaTeX 2e, Notas de estudo de Jornalismo

Toggle sidebar
bg1
Using Imported Graphics in L
A
T
EX2
ε
Keith Reckdahl
Version 2.0
December 15, 1997
Summary
This document explains how to use imported graphi cs in L
A
T
E
X2
εdocuments.
While reading the entire document is certainly worthwhile, most users should be
able to locate the necessary information by browsing the table of contents on
pages 3-5 or the index on pages 84-86.
While L
A
T
E
X can import virtually any graphics format, Encapsulated PostScript
(eps) is the easiest graphics format to import into L
A
T
E
X. For example, eps files
are inserted by specifying
\usepackage{graphicx}
in the document’s preamble and then using the command
\includegraphics{file.eps}
Optionally, the graphic can be scaled to a sp ecified height or width
\includegraphics[height=4cm]{file.eps}
\includegraphics[width=3in]{file.eps}
Additionally, the angle option rotates the included graphic
\includegraphics[angle=45]{file.eps}
The \includegraphicscommand and the rest of the L
A
T
E
X2
εgraphics bundle are
coveredinPartIIofthisdocument.
This document is divided i nto the following four parts
Part I: Background Information
This part provides historical information and describes basic L
A
T
E
Xterminol-
ogy. It also describes the Encapsulated PostScript (eps) format, differences
between eps and ps files, and methods for converting non-eps graphics to
eps.
Part I I: T he L
A
T
E
X Graphics Bundle
This part describes the commands in the graphics bundle which import, scale,
and rotate graphics. This part covers much of the information in the graphics
bundle documentation (reference [5]).
Part III: Using Graphics Inclusion Commands
This part describes how the graphics bundle commands are used to import,
rotate, and scale graphics. Three situations where graphics inclusion is mo d-
ified are also covered:
•Compressed eps files and non-eps graphic formats (tiff,gif,jpeg,
pict, etc.) can also be inserted on-the-fly when dvips is used with an
operating system which supports pipes (such as Unix). When using
other operating systems, the non-eps graphics must be converted to
eps beforehand.
Since neither L
A
T
E
Xnor dvips has any buil t-in decompression or graphics-
conversion capabilities, that software must be provided by the user.
c
Copyright 1995-97 by Keith Reckdahl. All rights reserved. Reproduction and distribution is allowed
under terms of the gnu General Public License.
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56

Pré-visualização parcial do texto

Baixe Using Imported Graphics in LaTeX 2e e outras Notas de estudo em PDF para Jornalismo, somente na Docsity!

Using Imported Graphics in LATEX 2ε

Keith Reckdahl

[email protected]

Version 2.

December 15, 1997

Summary This document explains how to use imported graphics in LATEX 2ε documents. While reading the entire document is certainly worthwhile, most users should be able to locate the necessary information by browsing the table of contents on pages 3-5 or the index on pages 84-86. While LATEX can import virtually any graphics format, Encapsulated PostScript

(eps) is the easiest graphics format to import into LATEX. For example, eps files

are inserted by specifying \usepackage{graphicx} in the document’s preamble and then using the command \includegraphics{file.eps} Optionally, the graphic can be scaled to a specified height or width \includegraphics[height=4cm]{file.eps} \includegraphics[width=3in]{file.eps} Additionally, the angle option rotates the included graphic \includegraphics[angle=45]{file.eps} The \includegraphics command and the rest of the LATEX 2ε graphics bundle are covered in Part II of this document.

This document is divided into the following four parts Part I: Background Information This part provides historical information and describes basic LATEX terminol-

ogy. It also describes the Encapsulated PostScript (eps) format, differences

between eps and ps files, and methods for converting non-eps graphics to

eps.

Part II: The LATEX Graphics Bundle This part describes the commands in the graphics bundle which import, scale, and rotate graphics. This part covers much of the information in the graphics bundle documentation (reference [5]). Part III: Using Graphics Inclusion Commands This part describes how the graphics bundle commands are used to import, rotate, and scale graphics. Three situations where graphics inclusion is mod- ified are also covered:

  • Compressed eps files and non-eps graphic formats (tiff, gif, jpeg,

pict, etc.) can also be inserted on-the-fly when dvips is used with an

operating system which supports pipes (such as Unix). When using

other operating systems, the non-eps graphics must be converted to

eps beforehand.

Since neither LATEX nor dvips has any built-in decompression or graphics- conversion capabilities, that software must be provided by the user.

© c Copyright 1995-97 by Keith Reckdahl. All rights reserved. Reproduction and distribution is allowed under terms of the gnu General Public License.

  • Since many graphics applications support only ascii text, the psfrag

system allows text in eps files to be replaced with LATEX symbols or

mathematical expressions.

  • When an eps graphic is inserted multiple times (such as a logo behind the text or in the page header) the final PostScript includes multiple copies of the graphics. When the graphics are not bitmapped, a smaller final PostScript file can be obtained by defining a PostScript command for the graphics. Part IV: The figure Environment There are several advantages to placing graphics in figure environments. Fig- ure environments automatically number graphics, allowing them to be ref- erenced or included in a table of contents. Since the figures can float to avoid poor page breaks, it is much easier to produce a professional-looking document. In addition to general information about the figure environment, this section describes the following figure-related topics:
  • How to customize the figure environment, such as adjusting figure place- ment, figure spacing, caption spacing, and adding horizontal line be- tween the figure and the text. Caption formatting can also be cus- tomized, allowing users to modify the style, width, and font of captions.
  • How to create marginal figures and wide figures which extend into the margins.
  • How to produce figures with landscape orientation in a portrait docu- ment.
  • How to place captions beside the figure instead of below or above the figure.
  • For two-sided documents, how to ensure that a figure appears on an odd or even page. Also, how to ensure that two figures appear on facing pages.
  • How to create boxed figures.
  • How to form side-by-side graphics, side-by-side figures, and side-by-side subfigures.
  • How to construct continued figures which can span multiple pages.

Where to Get this Document

This document is available in PostScript form as CTAN/info/epslatex.ps or in pdf form as CTAN/info/epslatex.pdf, where CTAN can be replaced by any of the following

ctan (Comprehensive TEX Archive Network) sites and mirrors

England ftp://ftp.tex.ac.uk/tex-archive/ Deutschland ftp://ftp.dante.de/tex-archive/ Eastern U.S. ftp://tug2.cs.umb.edu/tex-archive/ Western U.S. ftp://ftp.cdrom.com/pub/tex/ctan/ Australia ftp://unsw.edu.au/tex-archive/ Japan ftp://ftp.riken.go.jp/pub/tex-archive/

A complete list of ctan mirrors can be obtained from the CTAN.sites file at any

ctan site, or by fingering [email protected]

Acknowledgements I thank David Carlisle for providing me with a great deal of assistance. I also thank Donald Arseneau, Robin Fairbairns, Jim Hafner, Piet van Oostrum, and other contrib- utors to the comp.text.tex newsgroup, whose posts provided much of the information for this document. Thanks also goes to the many people who provided me with valuable

  • I Background Information
  • 1 Introduction
  • 2 LATEX Terminology
  • 3 Encapsulated PostScript
    • 3.1 Forbidden PostScript Operators
    • 3.2 The EPS BoundingBox
    • 3.3 Converting PS files to EPS
    • 3.4 Fixing Non-standard EPS files
  • 4 How EPS Files are Used by LATEX
    • 4.1 Line Buffer Overflow
  • 5 Obtaining GhostScript
  • 6 Graphics-Conversion Programs
    • 6.1 Level 2 EPS Wrappers
    • 6.2 Editing PostScript
  • II The LATEX Graphics Bundle
  • 7 EPS Graphics Inclusion
    • 7.1 The includegraphics Command
  • 8 Rotating and Scaling Objects
    • 8.1 The scalebox Command
    • 8.2 The resizebox Commands
    • 8.3 The rotatebox Command
  • 9 Advanced Commands
    • 9.1 The DeclareGraphicsExtensions Command
    • 9.2 The DeclareGraphicsRule Command
  • III Using Graphics-Inclusion Commands
  • 10 Horizontal Spacing and Centering
    • 10.1 Horizontal Centering
    • 10.2 Horizontal Spacing
  • 11 Rotation, Scaling, and Alignment
    • 11.1 Difference Between Height and Totalheight
    • 11.2 Scaling of Rotated Graphics
    • 11.3 Alignment of Rotated Graphics
    • 11.4 Minipage Vertical Alignment
  • 12 Using Subdirectories
    • 12.1 TEX Search Path
    • 12.2 Graphics Search Path
    • 12.3 Conserving Pool Space
  • 13 Compressed and Non-EPS Graphics Files
    • 13.1 Compressed EPS Example
    • 13.2 TEX Search Path and dvips
    • 13.3 Non-EPS Graphic Files
  • 14 The PSfrag Package
    • 14.1 PSfrag Example #1
    • 14.2 PSfrag Example #2
    • 14.3 LATEX Text in EPS File
    • 14.4 Figure and Text Scaling with PSfrag
    • 14.5 PSfrag Incompatibilities
  • 15 Including An EPS File Multiple Times
    • 15.1 Defining a PostScript Command
    • 15.2 Graphics in Page Header or Footer
    • 15.3 Watermark Graphics in Background
  • IV The Figure Environment
  • 16 The Figure Environment
    • 16.1 Creating Floating Figures
    • 16.2 Figure Placement
    • 16.3 Clearing Unprocessed Floats
    • 16.4 Too Many Unprocessed Floats
  • 17 Customizing Float Placement
    • 17.1 Float Placement Counters
    • 17.2 Figure Fractions
    • 17.3 Suppressing Floats
  • 18 Customizing the figure Environment
    • 18.1 Figure Spacing
    • 18.2 Horizontal Lines Above/Below Figure
    • 18.3 Caption Vertical Spacing
    • 18.4 Caption Label
    • 18.5 Moving Figures to End of Document
  • 19 Customizing Captions with caption2
    • 19.1 Caption Styles
    • 19.2 Changing the Caption Style
    • 19.3 One-Line Captions
    • 19.4 Caption Widths
    • 19.5 Caption Delimiter
    • 19.6 Caption Font
    • 19.7 Custom Caption Styles
    • 19.8 Linebreaks in Captions
    • 19.9 Adjusting Caption Linespacing
  • 20 Non-Floating Figures
    • 20.1 The float Package’s [H] Placement Option
  • 21 Marginal Figures
  • 22 Wide Figures
    • 22.1 Wide Figures in One-sided Documents
    • 22.2 Wide Figures in Two-sided Documents
  • 23 Landscape Figures
    • 23.1 Landscape Environment
    • 23.2 Sidewaysfigure Environment
    • 23.3 Rotcaption Command
  • 24 Captions Beside Figures
    • 24.1 Caption to Left of Figure
    • 24.2 Caption on Binding Side of Graphic
    • 24.3 The Sidecap Package
  • 25 Figures on Even or Odd Pages
    • 25.1 Figures on Facing Pages
  • 26 Boxed Figures
    • 26.1 Box Around Graphic
    • 26.2 Box Around Figure and Caption
    • 26.3 Customizing fbox Parameters
    • 26.4 The Fancybox Package
  • 27 Side-by-Side Graphics
    • 27.1 Side-by-Side Graphics in a Single Figure
    • 27.2 Side-by-Side Figures
    • 27.3 Side-by-Side Subfigures
  • 28 Stacked Graphics
  • 29 Placing a Table Beside a Figure
  • 30 Continued Figures
    • References
    • Index

cases, this graphics conversion can be performed on-the-fly by the dvi-to-ps converter.

Section 6 describes graphics-conversion programs while Section 13 describes how to use

non-eps graphics in LATEX.

2 LATEX Terminology

A box is any LATEX object (characters, graphics, etc.) that is treated as a unit (see [1, page 103]). Each box has a reference point on its left side. The box’s baseline is a horizontal line which passes through the reference point (see Figure 1). When LATEX forms lines of text, characters are placed left-to-right with their reference points aligned on a horizontal line called the current baseline, aligning the characters’ baselines with the current baseline. LATEX follows the same process for typesetting graphics or other objects; the reference point of each object is placed on the current baseline.

Baseline

depth

totalheight

height

width

Point

Reference

Figure 1: Sample LATEX Box

The size of each box is described by three lengths: height, depth, width. The height is the distance from the reference point to the top of the box. The depth is the distance from the reference point to the bottom of the box. The width is the width of the box. The totalheight is defined as the distance from the bottom of the box to the top of the box, or totalheight=height+depth.

The reference point of a non-rotated eps graphic is its lower-left corner (see left

Reference (^) depth

height

width

depth

width

height

Point

EPS Graphics EPS Graphics

EPS Graphics

width

Figure 2: Rotated LATEX Boxes

box in Figure 2), giving it zero depth and making its totalheight equal its height. The middle box in Figure 2 shows a rotated graphic where the height is not equal to the totalheight. The right box in Figure 2 shows a rotated graphic where the height is zero.

3 Encapsulated PostScript

The PostScript language can describe graphics and text. The PostScript language is

used in conventional PostScript (ps) files to describe multiple-page documents and also

in Encapsulated PostScript (eps) files to describe graphics for insertion into documents.

There are two main differences between PS and EPS files

  • EPS files can contain only certain PostScript operators.
  • EPS files must contain a BoundingBox line which specifies the size of the EPS graphic.

3.1 Forbidden PostScript Operators

Since eps graphics must share the page with other objects, the commands in an eps

file cannot perform page operations such as selecting a page size (such as letter or a4) or erasing the entire page with erasepage. The following PostScript operators are not

allowed in eps files:

a3 a4 a5 banddevice clear cleardictstack copypage erasepage exitserver framedevice grestoreall initclip initgraphics initmatrix letter legal note prenderbands quit renderbands setdevice setglobal setpagedevice setpageparams setsccbatch setshared startjob stop

Although the following PostScript operators can be used in eps files, they may cause

problems if not used properly.

nulldevice setcolortransfer setgstate sethalftone setmatrix setscreen settransfer undefinedfont

Some of the above operators may cause the dvi-to-ps process to fail, while others

may cause strange problems like misplaced or invisible graphics. Since many of these operators do not affect the PostScript stack, these problems can often be eliminated by simply deleting the offending operator. Other cases may require more complicated hacking of the PostScript.

3.2 The EPS BoundingBox

By convention, the first line of a PostScript file specifies the type of PostScript and is then followed by a series of comments called the header or preamble. (Like LATEX, PostScript’s comment character is %). One of these comments specifies the Bounding- Box. The BoundingBox line contains four integers

  1. The x-coordinate of the lower-left corner of the BoundingBox.
  2. The y-coordinate of the lower-left corner of the BoundingBox.
  3. The x-coordinate of the upper-right corner of the BoundingBox.
  4. The y-coordinate of the upper-right corner of the BoundingBox.

For example, the first 5 lines of an eps file created by gnuplot are

%!PS-Adobe-2.0 EPSF-2. %%Creator: gnuplot %%DocumentFonts: Times-Roman %%BoundingBox: 50 50 410 302 %%EndComments

must be fixed to remove the non-standard extensions. dos versions of Mathemat-

ica 2.x include a utility called either printps.exe or rasterps which removes the non-standard extensions. On Unix versions of Mathematica 2.x, this can be done with the psfix utility. Reference your Mathematica documentation or contact Wolfram Research for more information.

FrameMaker PostScript produced by FrameMaker fails to follow Adobe’s specification for page independence. PostScript files produced by FrameMaker Version 4 and 5 can be respectively fixed using the scripts

ftp://ftp.irisa.fr/pub/FrameMaker/Filters/fixfm4-1.3.tar.gz ftp://ftp.irisa.fr/pub/FrameMaker/Filters/fixfm5-2.0.tar.gz

Correction scripts for FrameMaker Version 3 and 4 are also available from

ftp://ftp.frame.com/pub/techsup/framers/platform.ind/filters/fixfm3ps.sh ftp://ftp.frame.com/pub/techsup/framers/platform.ind/filters/fixfm4ps.sh

4 How EPS Files are Used by LATEX

The eps files are used by both LATEX and the dvi-to-ps converter.

1. LATEX scans the eps file for the BoundingBox line, which tells LATEX how much

space to reserve for the graphic.

2. The dvi-to-ps converter then reads the eps file and inserts the graphics in the

ps file.

This has the following ramifications

  • LATEX never even reads the eps file if the BoundingBox parameters are specified in the graphics-insertion command (e.g., the bb option of \includegraphics is used).
  • Since TEX cannot read non-ascii files and cannot spawn other programs, LATEX

cannot read the BoundingBox information from compressed or non-eps graph-

ics files. In these cases, the BoundingBox parameters must be specified in the graphics-insertion command (e.g., in the bb option of the \includegraphics com- mand) or stored in a non-compressed text file (see Section 13).

  • The eps graphics are not included in the dvi file. Since the eps files must be

present when the dvi file is converted to ps, the eps files must accompany dvi

files whenever they are moved.

  • The eps graphics do not appear in most dvi viewers. To help the user with

placement of the graphics, dvi viewers generally display the BoundingBox in

which the graphics will be inserted. (Some viewers, such as xdvi, use ghostscript

to interpret the eps graphics and display them in the dvi viewer.)

4.1 Line Buffer Overflow

LATEX reads ascii files one line at a time, putting each line in its line buffer, which is

usually about 3000 characters long. If any of the lines of the eps file is longer than the

line buffer, the following error is displayed

Unable to read an entire line--bufsize=3000. Please ask a wizard to enlarge me.

Since eps rarely have lines longer than 3000 characters, there are two possible causes

of such an error

  1. The EPS file contains a long binary preview. Some applications place a binary preview of the graphics at the beginning of the

eps file. This allows applications (such as dvi viewers) to display the graphics

even though the application cannot interpret PostScript. Currently, relatively few TEX-related applications use such previews. If the binary preview is smaller than the line buffer, the \includegraphics com- mand skips over the preview (this is not the case with \psfig and other obsolete graphics commands). However, the overfull bufsize error occurs if the binary preview is larger than the line buffer. There are a couple work-arounds for this problem (a) If the preview won’t be used, the problem can be avoided by either deleting it with a text editor or by preventing the original graphics application from creating the preview.

(b) Since LATEX reads the eps file to only obtain the BoundingBox param-

eters, LATEX does not read the eps file if the BoundingBox parameters

are provided by the graphics-insertion command (e.g., the bb option to \includegraphics)

  1. The file’s end-of-line characters are corrupted by an improper transfer. (The problem described in this section does not occur with the latest web2c distri- bution and some commercial distributions whose TEX are smart enough to identify all end-of-line characters.) Different platforms use different end-of-line characters: Unix uses a line feed char-

acter (^J), Macintosh uses a carriage return (^M), while dos/Windows uses a

carriage return and line feed pair (^M^J). For example, if an eps file is transferred

in binary mode from a Macintosh to a Unix machine, the Unix TEX doesn’t see any ^J end-of-line characters and thus thinks the entire file is one big line, overfilling the line buffer.

If the eps file has no binary sections (e.g., no binary preview and no embedded

graphics) this problem can be avoided by transferring the eps file in text mode.

However, eps files with binary sections must be transferred with binary mode,

since the text mode transfer may corrupt the binary section. However, such binary transfer results in incorrect end-of-line characters, requiring the BoundingBox information be provided by the graphics-insertion command (e.g., the bb option to \includegraphics).

5 Obtaining GhostScript

Ghostscript is a PostScript interpreter which runs on most platforms and is distributed for free^2 by Aladdin Enterprises. This allows PostScript and EPS files to be displayed on the screen and printed to non-PostScript printers. Aladdin Ghostscript is avail- able from CTAN/support/ghostscript/aladdin/. It is also available directly from the Ghostscript home page http://www.cs.wisc.edu/~ghost/index.html

whose html interface provides better directions than do the ctan ftp sites.

These sites contains pre-compiled Windows/dos/OS/2 and Macintosh executables,

along with ready-to-compile source code for Unix/vms. Also available are graphi-

cal interfaces (GSview for Windows 3.1/95/NT/OS/2, Ghostview for Unix/vms) for

Ghostscript which makes the viewing of PostScript much easier.

(^2) Although Aladdin Ghostscript is distributed for free, it is not in the public domain. It is copyrighted and comes with certain limitations such as no commercial distribution. When versions of Aladdin Ghostscript become approximately one year old, Aladdin releases them as “GNU Ghostscript” whose use is governed by the less-restrictive GNU Public License.

  • A tiff graphic can be converted to lzw-encoded Level-2 PostScript by using tiff2ps, whose source is available from ftp://ftp.sgi.com/graphics/tiff/tiff-v3.4-tar.gz

A tar.Z file is also available. tiff2ps can be compiled on Unix, dos, Mac,

and vms platforms. Although the lzw PostScript files are small, they require a

Level-2 PostScript printer.

6.2 Editing PostScript

While the graphics in an eps file can be modified by editing the file’s PostScript com-

mands, this is difficult for most people. Instead, it is easier to use the following programs

to edit eps graphics

  • pstoedit is a free program for Unix, dos, Windows, and OS/2 whose C++ source code is available from ftp://ftp.x.org/contrib/applications/pstoedit/pstoedit.html http://www.cdrom.com/pub/X11/contrib/applications/pstoedit/

when used with ghostscript, pstoedit translates PostScript and pdf graphics

into other vector formats (such as xfig’s .fig format).

  • Mayura Draw (formerly known as PageDraw) is a drawing program for Windows 3.1/95/NT which is available from http://www.wix.com/PageDraw When used with ghostscript, Mayura Draw can edit PostScript files. Older versions of Mayura Draw are distributed for free, while more recent versions are $15 shareware. Note that Mayura Draw requires Adobe Type Manager (ATM) to place text on the graphics. Although ATM is now commercial software, Adobe formerly distributed it for free with Acrobat Reader 2.0, which is available from Winsite at ftp://ftp.winsite.com/pub/pc/win3/util/acroread.zip
  • xfig is a free drawing program for Unix/Xwindows available from ftp://ftp.x.org/contrib/applications/drawing_tools/ http://www.cdrom.com/pub/X11/contrib/applications/drawing_tools/ xfig can import EPS drawings and add annotations, but currently cannot modify

the original eps graphics.

Part II

The LATEX Graphics Bundle

7 EPS Graphics Inclusion

The best reference for the graphics and graphicx packages is the graphics guide [5] or the LATEX Graphics Companion [4]. The coverage of the graphicx package in other LATEX references is sporadic: [2] covers both the graphics and graphicx packages, [1] only covers the graphics package and [3] describes neither.

7.1 The includegraphics Command

Syntax: \includegraphics[options]{filename}

where the options are listed in Tables 1, 2, and 3. Since \includegraphics does not end the current paragraph, it can place graphics within text such as or. The commands \documentclass{article} \usepackage{graphicx} \begin{document} \includegraphics{file.eps} \end{document} include the graphics from file.eps at its natural size. When the specified filename has no extension \includegraphics appends the ex- tensions in the \DeclareGraphicsExtensions extension list (See Section 9.1). Since the default extension list does not include the null extension, \includegraphics{file} does not read file unless the null extension is added to the extension list.

Table 1: includegraphics Options

height The height of the graphics (in any of the accepted TEX units). totalheight The totalheight of the graphics, in any of the accepted TEX units. (Added 6/95) width The width of the graphics, in any of the accepted TEX units. scale Scale factor for the graphic. Specifying scale=2 makes the graphic twice as large as its natural size. angle Specifies the angle of rotation, in degrees, with a counter-clockwise (anti-clockwise) rotation being positive. origin The origin command specifies what point to use for the rotation origin. By default, the object is rotated about its reference point. (Added 12/95) The possible origin points are the same as those for the \rotatebox command in Section 8.3. For example, origin=c rotates the graphic about its center. bb Specifies BoundingBox parameters. For example bb=10 20 100 200 specifies that the BoundingBox has its lower-left corner at (10,20) and its upper-right corner at (100,200). Since \includegraphics automatically reads the BoundingBox parameters from the

eps file, the bb option is usually not specified. It is useful if the BoundingBox pa-

rameters in the eps file are missing or incorrect.

Specifying The command Width (^) \includegraphics[width=3in]{file.eps} includes the graphics from file.eps scaled such that its width is 3 inches. Instead of making the width be a fixed length such as 3 inches, making the width of function of \textwidth or \em makes a document more portable. For example, the command

\includegraphics[width=\textwidth]{graphic.eps}

scales the included graphic such that it is as wide as the text. The command

\includegraphics[width=0.80\textwidth]{graphic.eps}

makes the included graphic 80% as wide as the text. When the calc package is used, the following command make the graphic width 2 inches less than the width of text

\includegraphics[width=\textwidth-2.0in]{graphic.eps}

(This requires graphicx version 12/95 or later).

8 Rotating and Scaling Objects

In addition to the \includegraphics command, the graphicx package includes 4 other

commands which rotate and scale any LATEX object: text, eps graphic, etc.

\scalebox{h-scale}[v-scale]{argument} \resizebox{width}{height}{argument} \resizebox*{width}{totalheight}{argument} \rotatebox[options]{angle}{argument}

Since the graphicx \includegraphics command supports rotating and scaling options such as angle and width, the commands in this section rarely need to be used with

eps graphics. For example,

\includegraphics[scale=2]{file.eps} \includegraphics[width=4in]{file.eps} \includegraphics[angle=45]{file.eps}

produce the same three graphics as

\scalebox{2}{\includegraphics{file.eps}} \resizebox{4in}{!}{\includegraphics{file.eps}} \rotatebox{45}{\includegraphics{file.eps}}

However, the first syntax is preferred because it is faster and produces more efficient PostScript.

8.1 The scalebox Command

Syntax: \scalebox{h-scale}[v-scale]{argument}

The \scalebox command scales an object, making its width be h-scale times its original width and making the object’s height be v-scale times its original height. If v-scale is omitted, it defaults to h-scale, keeping the aspect ratio constant. Negative values reflect the object.

8.2 The resizebox Commands

Syntax: \resizebox{width}{height}{argument}

\resizebox*{width}{totalheight}{argument}

The \resizebox command resizes an object to a specified size. Specifying! as either height or width makes that length be such that the aspect ratio remains constant. For example, \resizebox{2in}{!}{argument} scales the argument to be 2 inches wide. The standard LATEX 2ε arguments \height, \width, \totalheight, \depth can be used to refer to the original size of argument. So \resizebox{2in}{\height}{argument} makes argument keep its same height but have a width of 2 inches. The \resizebox* command is identical to \resizebox, except the second argument specifies the totalheight of the object.

8.3 The rotatebox Command

Syntax: \rotatebox[options]{angle}{argument}

The \rotatebox command rotates an object by an angle given in degrees, with a counter-clockwise rotation being positive. By default, the object is rotated about its reference point. The \rotatebox options allow the point of rotation to be specified.

  1. Specifying the [x=xdim,y=ydim], the object is rotated about the point whose coordinates relative to the reference point are (xdim,ydim).
  2. The origin option specifies one of 12 special points shown in in Figure 3.

Reference

Point

Baseline

Centerlines

[lt]

[lc]

[lB]

[lb]

[ct]

[c]

[cB]

[cb]

[rt]

[rc]

[rB]

[rb]

Figure 3: Available Origin Points

The horizontal position of the origin points is specified by one of three letters: lcr (which stand for left, center, right, respectively), while the vertical position is specified by one of four letters: t,c,B,b (which stand for top, center, Baseline, bottom, respectively). For example [rb] specifies the bottom-right corner [lt] specifies the top-left corner [cB] specifies the center of the graphic’s Baseline Note that

  • The order of the letters is not important, making [br] equivalent to [rb].
  • c represents either the horizontal center or vertical center depending what letter is used with it.
  • If only one letter is specified, the other is assumed to be c, making [c] equivalent to [cc], [l] equivalent to [lc], [t] equivalent to [tc], etc.

9 Advanced Commands

This section describes advanced commands which are needed in the following situations

  1. When the specified filename has no extension. For example \includegraphics{file}

2. When compressed eps graphics are used (see Section 13.1).

  1. When non-EPS graphics are used (see Section 13.3).

In these situations, the \DeclareGraphicsRule and \DeclareGraphicsExtensions commands are needed to control how LATEX deals with files specified in \includegraphics.

Table 4: DeclareGraphicsRule Arguments

ext The file extension. type The graphics type for that extension. sizefile The extension of the file which contains the BoundingBox information for the graph- ics. If this option is blank, then the size information must be specified by the \includegraphics command’s bb option. command The command to be applied to the file. (often left blank). The command must be preceded by a single backward quote (not to be confused with the more common forward single quote.) Currently, only dvips allows execution of such a command. See Section 13 for examples of using this command for use with compressed and non-

eps graphics.

specifies that any file with a .eps.gz extension is treated as compressed eps file, with

the the BoundingBox information stored in the file with a .eps.bb extension, and the gunzip -c command uncompresses the file. (Since LATEX cannot read BoundingBox information from a compressed file, the BoundingBox line must be stored in an uncom- pressed file.) The \DeclareGraphicsRule allows * to signify any unknown extension. For exam- ple,

\DeclareGraphicsRule{}{eps}{}{}

causes any unknown extension to be treated as an eps file. For example, this causes

file.EPS) to be treated as a an eps file.

Periods In The extension is defined as the portion of the filename after the first period, which

Filenames makes it possible for files ending in eps.gz to be identified as compressed eps files. To

avoid confusion, the base portion of the filename should not contain a period. For ex- ample, specifying file.name.eps.gz makes \includegraphics look for a graphics rule associated with the extension name.eps.gz. Since such a graphics rule probably does not exist, the graphics rule for the unknown extension is used. (Filenames with multiple periods work if their type happens to be the default type. For example, when files with

unknown extensions are treated as eps, the filename file.name.eps is coincidently

treated correctly.) Pre-defined For convenience, a default set of graphics rules is pre-defined depending on which Commands graphics driver is selected^4.^ For example if the^ dvips^ driver is used, the following graphic rules (defined in dvips.def) are used by default \DeclareGraphicsRule{.eps}{eps}{.eps}{} \DeclareGraphicsRule{.ps}{eps}{.ps}{} \DeclareGraphicsRule{.pz}{eps}{.bb}{‘gunzip -c #1} \DeclareGraphicsRule{.eps.Z}{eps}{.eps.bb}{‘gunzip -c #1} \DeclareGraphicsRule{.ps.Z}{eps}{.ps.bb}{‘gunzip -c #1} \DeclareGraphicsRule{.eps.gz}{eps}{.eps.bb}{‘gunzip -c #1} \DeclareGraphicsRule{.ps.gz}{eps}{.ps.bb}{‘gunzip -c #1} \DeclareGraphicsRule{.pcx}{bmp}{}{} \DeclareGraphicsRule{.bmp}{bmp}{}{} \DeclareGraphicsRule{.msp}{bmp}{}{} \DeclareGraphicsRule{}{eps}{}{}

The first two commands define the .eps and .ps extensions as eps files. The next five

commands define extensions for compressed eps files. The next three commands define

extensions for bitmaps (see Section 13.3.2). The last command causes filenames with

unknown extensions to be treated as an eps file.

(^4) Specifying a graphics-driver package option such as \usepackage[dvips]{graphicx} overrides the default graphics driver specified in the graphics.cfg file.

Part III

Using Graphics-Inclusion Commands

10 Horizontal Spacing and Centering

10.1 Horizontal Centering

The placement of the graphic is controlled by the current text justification. To center the graphic, put it inside a center environment \begin{center} \includegraphics[width=2in]{graphic.eps} \end{center} If the \includegraphics command is inside an environment (such as minipage or figure), the \centering declaration centers the remaining output of the environment. For example \begin{figure} \centering \includegraphics[width=2in]{graphic.eps} \end{figure} is similar to \begin{figure} \begin{center} \includegraphics[width=2in]{graphic.eps} \end{center} \end{figure} The \centering syntax is preferred because the \begin{center} syntax produces dou- ble vertical space above and below the figure due to the space produced by the figure environment and by the center environment. If extra vertical space is desired, the commands in Section 18.1 should be used. Obsolete Bugs in the \psfig and \epsfbox commands made it difficult to produce horizontally- Syntax centered graphics. The TEX commands \centerline and \leavevmode were used as work-arounds for bugs in \psfig and \epsfbox. Since the \includegraphics command is written correctly, the \centerline and \leavevmode are no longer needed, allowing graphics to be centered with the \centering command or the center environment.

10.2 Horizontal Spacing

It is important to realize that LATEX arranges graphics the same way it formats other objects such as letters. For example, an interword space is introduced between LATEX input lines unless the line ends with a %. For example, just as Hello World put an interword space between “Hello” and “World” \includegraphics{file.eps} \includegraphics{file.eps} puts an interword space between the graphics. Ending the first line with a comment character \includegraphics{file.eps}% \includegraphics{file.eps} puts no space between the graphics. When horizontal spacing is desired between graph- ics, the \hspace command inserts a specific amount of space^5 while \hfill inserts a rubber length which provides which expands to fill the available space. For example, (^5) Instead of making the \hspace amount a fixed length such as 1 inch, making the \hspace amount a function of \textwidth or \em increases a document’s portability.