How to insert figures into LaTeX articles

A LaTeX version of this paper is available here . You might find it more useful, as it is a working file that can be compiled, and then edited to see what changing various bits and pieces does. The postscript that this file produces is here (1.2Mb).

Inserting single figures into LaTeX articles

First off, you have to have some text in your file before you can include any diagrams without LaTeX complaining.

Then you can insert a picture with something like:

\begin{figure}[htp]
\centering
\includegraphics{erptsqfit}
\caption{Transverse momentum distributions}\label{fig:erptsqfit}
\end{figure}
A slightly more complicated version looks like the below example. This is used to select only a portion of your picture, and the part of the caption in square brackets is taken as the caption in a list of figures. This means that you can format the caption that appears with your figure differently to the way it will appear in the list of figures. Also, the figure caption will typically be longer, and more detailed than that which appears in the list of figures.
\begin{figure}[htp]
\centering
\includegraphics[totalheight=0.8\textheight,viewport=50 260 400 1000,clip]{erptsqfit}
\caption[Transverse momentum distributions - E-R model.]
{Transverse momentum distributions - E-R model fit (intercept 1.2).}\label{fig:erptsqfit}
\end{figure}


The most useful option to use, I find, is to set the width or height you want your picture scaled to to be some fraction of the textwidth or height, as is done in the above, where we have [totalheight=0.8\textheight], that is, the total height of the figure is set to 80\,\% of the height of the text on a normal page of typing.

The viewport command needs some fiddling with to get right - if you choose to use it at all (you need it for mathematica files as they are saved very very poorly as PS files). Basically it's the number of points to take off the top, left, bottom, right, in that order, I think. You just have to play around and see. The idea is, it takes this much space off all around the document, leaving only the inside bit that is what you want to see in your document. You need the ``clip'' command to force LaTeX to ignore the stuff outside the limits you specify by ``viewport''.

Multiple figures

Multiple figures can be inserted in this manner (where here I have just used the same figure several times). The \hfill command gives you a nice spacing between the figures.
\begin{figure}[htp]
\centering
\includegraphics[width=0.4\textwidth,viewport=50 260 400
1000,clip]{erptsqfit}
\hfill
\includegraphics[width=0.4\textwidth,viewport=50 260 400 1000,clip]{erptsqfit}\\
\includegraphics[width=0.4\textwidth,viewport=50 260 400
1000,clip]{erptsqfit}
\hfill
\includegraphics[width=0.4\textwidth,viewport=50 260 400 1000,clip]{erptsqfit}\\
\caption[Transverse momentum distributions - E-R model.]{Transverse momentum distributions - E-R model fit
(intercept 1.2).}\label{fig:erptsqfit}
\end{figure}

Subfigures

However, sub-figures using the subfigure package in LaTeX is really the way to do this!! This package come with the standard distribution of LaTeX, is called using
\usepackage{subfigure}
in the document preamble (i.e. before the \begin{document} command).

A nice example of the use of this package to create a 2x2 figure is as follows

\begin{figure}%[htp]
     \centering
     \subfigure[Donnachie-Landshoff form factor model in Feynman gauge
     (solid line) and in non-covariant gauge (dashed line). Here
     $\Lambda=0.2\gev^2$ and $\intercept=1.08$.]{
          \label{fig:dl2858}
                \psfrag{ylabel}{$\frac{1}{\sigma}\frac{\rmd\sigma}{\rmd\ptsq}\gev^2$}
                \psfrag{xlabel}{\small{$\ptsq\gev^2$}}
          \includegraphics[width=.45\textwidth]{dlddlanalysis99fit2858loglin.eps}}
     \hspace{.3in}
     \subfigure[Ellis-Ross form factor model in Feynman gauge (solid
     line) and in non-covariant gauge (dashed line). Here
     $\Lambda=0.2\gev^2$ and $\intercept=1.08$.]{
          \label{fig:er2858}
                \psfrag{ylabel}{$\frac{1}{\sigma}\frac{\rmd\sigma}{\rmd\ptsq}\gev^2$}
                \psfrag{xlabel}{\small{$\ptsq\gev^2$}}
          \includegraphics[width=.45\textwidth]{erderanalysis99fit2858loglin.eps}}\\
     \vspace{.3in}
%     \hspace{.1in}
     \subfigure[Single-gluon exchange model (solid line) and Scalar
     Pomeron exchange model (dashed line).]{
           \label{fig:cminusscalar2858}
                \psfrag{ylabel}{$\frac{1}{\sigma}\frac{\rmd\sigma}{\rmd\ptsq}\gev^2$}
                \psfrag{xlabel}{\small{$\ptsq\gev^2$}}
           \includegraphics[width=.45\textwidth]
                {cminusscalaranalysis99fit2858loglin.eps}}
     \subfigure[Two-gluon exchange model.]{
           \label{fig:2glue2858}
                \psfrag{ylabel}{$\frac{1}{\sigma}\frac{\rmd\sigma}{\rmd\ptsq}\gev^2$}
                \psfrag{xlabel}{\small{$\ptsq\gev^2$}}
          \includegraphics[width=.45\textwidth]{2glueanalysis99fit2858loglin.eps}}
     \caption{Fit of pomeron models to Thrust Jet
           data\,\cite{Adloff:1997sc}. The fit is only made to points
           after the turn-over of the curves. Curves correspond to
           model fits, while solid points are H1 data. These plots
           show the fits for several models for diffractive masses in
           the region of $M_X=28.58\gev$. The statistical and
           systematic errors have been added in quadrature.}
     \label{fig:2858multifig}
\end{figure}

Other useful figure items


Last modified: Thur 5 Aug 1.53 AM BST Copyright © 1999  Jenny Williams Email: physjcw@thphys.ox.ac.uk