Help @ MC
LaTeX
Centre for Mathematical Sciences, Lund University
Home

Up to Help

BibTeX
Graphics
PDF
TeX-system @ MClocal

Tools
maketex

Packages
PSTricks
Local:
mccover
mcslides
(prosper)

*LaTeX Help 1.4
*TeX FAQ
*Complete TeX Catalog
*Att skriva rapport i LaTeX av Per Foreby
*CTAN
*TeX Primitive Control Sequences
*MikTeX (LaTeX for Windows)
*ps2pdf.com
*TexPoint
*Ghostscript & Ghostview

Printer-friendly
Print this page

Graphics in LaTeX

Henrik Bengtsson, 2003-09-01

1. Package graphicx - Importing graphics

To import graphics in LaTeX we recommend you to use the graphicx package (note the x at the end). The precursor to graphicx is the graphics package, which is obsolete and should not be used. The graphicx package provides user-friendly methods for placing, rescaling, rotating etc eps figures. Here is an example that imports the file crossover-def.eps in the subdirectory figures and rescale the size so the height is 80mm and the width is proportional (!) to the height. The figure is centered and has a caption and the figure can be refered to in the text by its label, i.e. \ref{Meiosis}.


\usepackage{graphicx}

[snip]

\begin{figure}[hbt]
\begin{center}
\resizebox{!}{80mm}{\includegraphics{figures/crossover-def.eps}}
\end{center}
\caption{A simplified picture of meiosis when one chromosome
of the mother or father is formed. The dark and light
segments correspond the grandfather's and grandmother's
DNA strands respectively. In this picture, two crossovers
occur.}
\label{Meiosis}   % <-- IMPORTANT: \label is *after* \caption
\end{figure}


Details: The options [hbt] to the figure enviroment is helping LaTeX to place the figure on the page, by saying it is ok to place it "here" (h), at the bottom (b) and at the top (t) of the page. There is also a fourth option available, namely p, but we recommend you not to use this option.

1.1 Problems getting figures & tables where you want them?

"Floats are page elements that float with respect to the rest of the document. Standard floats are tables and figures. Most of the time floats work satisfactory, but sometimes LaTeX seems too stubborn to do what you want."

See document Float placement how to solve this and understand why it happens. See also Moving tables and figures in LaTeX, which also describes how to force figures and tables to the end of the document (the endfloat package).

1.2 Telling LaTeX where to look for graphics files

Put a \graphicspath anywhere in your LaTeX document. Example:

% Graphics files are in the figures/ directory
\graphicspath{{figures/}}


LaTeX will always look in the current directory also, so you do not have to specify that explicitly.

1.3 Importing compressed graphics, e.g. foo.eps.gz

To save disk space one can compress the *.eps files into *.eps.gz files (using gzip or maketex as below) and then use \includegraphics to import the graphics

  \includegraphics{figures/crossover-def.eps.gz}


However, since LaTeX needs the bounding box information found in the head of the eps file, this single line has to be extracted and saved into *.eps.bb before compressing the file. Example of a one-line *.eps.bb file:

%%BoundingBox: 118 259 478 583


For the above to work, the file names can only contain one dot, which is reserved for .eps so to speak. Legal file names are: myFabolousFigure.eps (myFabolousFigure.eps.gz and myFabolousFigure.eps.bb) and illegal names are: my.fabolous.figure.eps (my.fabolous.figure.eps.gz and my.fabolous.figure.eps.bb). The symptom for using illegal file names is the follow error:

! LaTeX Error: Cannot determine size of graphic in
my.fabolous.figure.eps.gz (no BoundingBox).


The maketex command is really useful for automatically extracting the bounding box from several eps files at once and the compressing them. In the directory where the graphics files are, just do

% maketex -gzip *.eps


and all the eps files will be automatically compressed. All the bounding box files are also generated. To correct illegal file names before trying to compress:

% maketex -fixeps *.eps