Icecafe’s Weblog

Whatever we want…

Insert figures into LaTeX articles

Posted by icecafe on February 15, 2008

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:

\caption{Transverse momentum distributions}\label{fig:erptsqfit}
  • Fig.[fig:erptsqfit] is your basic picture. The [htp] command works like usual to tell LaTeX how to position the graphic in the text.
  • The placement specifier p lets the figure take up a full page without waiting until the end of the chapter
  • centering tells LaTeX to centre everything within the graphics environment.
  • includegraphics is your basic command to include a graphics object. (The bits in […] shown below are various options that can be omitted. In the curly brackets is the name of the file you want included.) As you can see the extension of the graphics filename is omitted – LaTeX looks for this file with various possible extensions – .eps, .ps, … (Note: LaTeX will look for before filename.eps.)
  • the most important option in […] is the size. There are a few choices that are useful …
      [width=xxx cm], … [height=xxx cm], etc.

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.

\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}

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”.

  • The stuff in […] in the caption command tells LaTeX what to put in the table of contents. Otherwise is just uses the stuff in the curly brackets if you omit […]. The stuff in curly brackets is what appears as your figure caption.

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.

\includegraphics[width=0.4\textwidth,viewport=50 260 400
\includegraphics[width=0.4\textwidth,viewport=50 260 400 1000,clip]{erptsqfit}\\
\includegraphics[width=0.4\textwidth,viewport=50 260 400
\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}


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


in the document preamble (i.e. before the \begin{document} command).A nice example of the use of this package to create a 2×2 figure is as follows

     \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$.]{
     \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$.]{
%     \hspace{.1in}
     \subfigure[Single-gluon exchange model (solid line) and Scalar
     Pomeron exchange model (dashed line).]{
     \subfigure[Two-gluon exchange model.]{
     \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.}
\end{figure}    (source:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: