How to create a figure in LaTeX?

A figure in Latex can be used to insert images and vector drawings created by external applications, such as Xfig, Corel Draw, and Adobe Photoshop or Illustrator. A figure can also contain miscellaneous data that you may want to include in your application, such as tables, programming code, or charts, for example.

An important feature of LaTeX is that it handles images automatically. Material such as images is known as floats in TeX parlance. The TeX engine also decides exactly where the float will be located, which sometimes makes it difficult to control the position where the images will appear.

In LaTeX, the main command to add images is \includegraphics. The \includegraphics command is very versatile, however, with several options for positioning, rotation, and scaling of figures.

For example, here is the simplest way of adding an image:

\includegraphics{myimage}

Here, myimage is the name of the image file without the extension (which can be one of the major supported types, such as jpg, gif, or eps). This way, however, the image is added in the middle of the flow of paragraphs. To get the image properly positioned, you need to use the figure environment. For example:

\begin{figure}[t]
\includegraphics{myimage}
\end{figure}


Defining the position of the figure

The figure environment has options to define the position of the resulting figure. This is determined by the optional argument after the begin{figure}. In the example above, [t] determines that the figure will be positioned at the top of the page. Similarly, [b] would try to position the figure at the bottom, and [h] means that the figure will be positioned here, that is, in the position in which it appears in the text.

The indications can also be combined. For example, [tb] means that the figure will be positioned on the top first, and if there is no space, at the bottom. [bth] means that LaTeX will first try the bottom of the page, then the top, and finally will position the figure in the exact location where it appears.

It is important to remember, however, that the indication of the position is just a hint for LaTeX. That is, it also depends on how the elements of the page are disposed, and the TeX engine always try to optimize how the paragraphs and other elements of the page are disposed. For example, a page may include several figures with indication of top. However, LaTeX will not create multiple pages with only a single image on the top. Thus, the resulting typeset page will probably include images in other locations other than the top, and probably other text as necessary to fill the pages.

Article created on 2009-01-01 12:59:55