Skip to Main Content
The University of Massachusetts Amherst

LaTeX

Getting Started with Images

To add images (such as from your computer) to your LaTeX document, begin by creating a figure environment (\begin{figure}...\end{figure}). When creating your figure environment, you can use an optional argument to specify the placement of the image within your document using the following tokens:

  • hhere (approximately where the image is placed in the source code)
  • ttop of page
  • bbottom of page
  • ppage specifically for figure
  • HHere (exactly where the image is placed in the source code)
  • ! - use with another token to override LaTeX's logic for figure placement (example: b! would force the image to the bottom of the page)

You will also need to load the graphicx package in your document preamble (\usepackage{graphicx}).

Adding and Formatting Your Image

Inside the figure environment, use the following commands:

Use the command \includegraphics to insert a new image.

  • Specify the image you want to insert by typing the name of the file as a mandatory argument for the \includegraphics command. (Make sure that the image file is in the same directory/folder as the LaTeX document!)
  • You can also specify the width and/or height of the image by adding an optional argument.
  • Example: \includegraphics[width=0.75\linewidth]{FileName.png}

Use the command \caption to add a caption to your image.

  • Simply type the caption you want to appear with your image in a mandatory argument for the \caption command.
  • Example: \caption{An example of caption text.}

Use the following commands to specify the alignment of your image:

  • \raggedright - right-aligned
  • \centering - centered
  • \raggedleft - left-aligned

Example Image

List of Figures

You can add a List of Figures (with corresponding page numbers) at the beginning of your document using the command \listoffigures. This list will automatically update as you add new figures to your document. 

Referencing Your Images

LaTeX can assist with textual references to your images by giving each image a label.

  • In the figure environment, use the command \label{x} to label your image (Note: the "label" is separate from the caption and will not appear in any way in the document output. It is solely used as a way to reference the image in the source code)
    • Example: \label{Height}
  • In your text, use the command \ref{x} where you would like to reference the figure. In the mandatory argument, simply insert the label of the figure you would like to reference.
    • Example: We can see differences in height between the two groups in Fig. \ref{Height}. 


One advantage to setting up your references to images in this format is that you do not need to worry about moving figures around. LaTeX will automatically update the reference number if the images are put in a new order (e.g. if you insert a new image before "Figure 1" it will automatically become "Figure 2").