The basic way to add a photo in LaTeX

To add a photo in LaTeX, you use the graphicx package and the \includegraphics command. First, put this line in your document's preamble (the section before \begin{document}):

\usepackage{graphicx}

Then, in the body of your document where you want the photo to appear, write:

\includegraphics{filename.jpg}

Replace "filename.jpg" with the actual name of your image file. The image file must be in the same folder as your LaTeX document, or you need to provide the full path to where it lives on your computer.

Key Takeaways

  • Add \usepackage{graphicx} to the top of your document before \begin{document} to enable photo insertion.
  • Use \includegraphics{filename} to place a photo, and the file must be in the same folder as your .tex file or you must specify its full path.
  • Control photo size with the width or height option: \includegraphics[width=3cm]{filename.jpg}.
  • Wrap \includegraphics inside a figure environment to add captions, labels, and control where the photo sits on the page.
  • Common image formats that work are .jpg, .png, and .pdf, though .pdf works best with pdflatex.

Resizing photos so they fit your page

By default, LaTeX inserts the photo at its original size, which is often too large. Add the width or height option inside square brackets to resize it:

\includegraphics[width=5cm]{filename.jpg}

\includegraphics[height=3in]{filename.jpg}

You can use centimeters (cm), inches (in), or a percentage of the page width. If you set only width or only height, LaTeX automatically scales the other dimension to keep the photo from looking stretched. If you set both, the photo may distort, so avoid that.

A common approach is to make the photo as wide as the text on your page. Use \textwidth to do this:

\includegraphics[width=0.8\textwidth]{filename.jpg}

This makes the photo 80 percent as wide as your text area, leaving room for margins.

Adding captions and labels with the figure environment

If you want to add a caption below the photo or refer to it elsewhere in your document, wrap the \includegraphics command in a figure environment:

\begin{figure}[h] \includegraphics[width=5cm]{filename.jpg} \caption{This is the photo caption} \label{fig:myphoto} \end{figure}

The [h] tells LaTeX to place the figure "here" on the page, though LaTeX may move it slightly if it does not fit. Other options are [t] for top of page, [b] for bottom, and [p] for a page of figures only.

The \caption command adds text below the photo. The \label command lets you refer to the photo later by writing \ref{fig:myphoto}, which automatically inserts the figure number. This is useful when you write "See Figure \ref{fig:myphoto}" and then add more photos — the numbers update automatically.

Centering photos on the page

By default, photos sit at the left margin. To center a photo, wrap it in a center environment:

\begin{center} \includegraphics[width=4cm]{filename.jpg} \end{center}

If the photo is already inside a figure environment, you can center it this way:

\begin{figure}[h] \centering \includegraphics[width=4cm]{filename.jpg} \caption{Centered photo} \end{figure}

Use \centering instead of the center environment when you are inside a figure, because the center environment adds extra space that can push the caption away from the photo.

Placing photos side by side

To put two photos next to each other, use the minipage environment. Each minipage is a small box that can hold text or an image, and you can fit multiple minipages on one line:

\begin{figure}[h] \begin{minipage}{0.45\textwidth} \centering \includegraphics[width=\textwidth]{photo1.jpg} \caption{First photo} \end{minipage} \hfill \begin{minipage}{0.45\textwidth} \centering \includegraphics[width=\textwidth]{photo2.jpg} \caption{Second photo} \end{minipage} \end{figure}

Each minipage is 0.45 times the text width, leaving 0.1 times the width as space between them. The \hfill command pushes the minipages apart to fill the available space. You can adjust the 0.45 value to make the photos wider or narrower.

Fixing common problems with image files

If LaTeX cannot find your image, check that the filename is spelled exactly right, including the file extension (.jpg, .png, or .pdf). File names are case-sensitive on Mac and Linux, so "Photo.jpg" is different from "photo.jpg".

If you are using pdflatex (the most common compiler), .pdf and .png files work reliably. Some older LaTeX setups have trouble with .jpg files. If your .jpg does not appear, convert it to .png using free tools like GIMP or an online converter, then update the filename in your code.

If the photo appears but looks blurry or pixelated, the original file may be low resolution. For printed documents, use photos that are at least 300 pixels per inch. For documents you only read on screen, 72 pixels per inch is enough.

Rotating and flipping photos

To rotate a photo, add the angle option:

\includegraphics[width=4cm, angle=90]{filename.jpg}

The angle is in degrees, measured counterclockwise. So angle=90 rotates the photo 90 degrees to the left, angle=180 flips it upside down, and angle=270 rotates it 90 degrees to the right.

To flip a photo horizontally (mirror it), use the scale option with a negative value:

\includegraphics[width=4cm, scale=-1]{filename.jpg}

Combining rotation and scaling works too: \includegraphics[width=4cm, angle=45, scale=-1]{filename.jpg} rotates and flips at the same time.

Frequently Asked Questions

What image formats work in LaTeX?

.jpg, .png, and .pdf all work with pdflatex, which is the standard compiler. .eps files work with older latex and dvips setups. Stick with .jpg or .png unless you have a specific reason to use something else.

Can I add a photo inside a table or text paragraph?

Yes. You can use \includegraphics anywhere in your document, including inside tables and paragraphs. The photo will sit inline with the text. If you want text to wrap around the photo, you need the wrapfig package, which is more complex — for most documents, putting the photo in its own figure environment is simpler.

Why does my photo appear on a different page than where I wrote the code?

LaTeX treats figure environments as "floating" objects, meaning it moves them to find the best place on the page. If you want the photo to stay exactly where you wrote it, use [h!] instead of [h]: \begin{figure}[h!]. The exclamation mark tells LaTeX to try harder to keep it in place, though it may still move if there is not enough room.

How do I make a photo the same width as a paragraph of text?

Use \includegraphics[width=\textwidth]{filename.jpg} to make the photo exactly as wide as your text. Use \includegraphics[width=0.9\textwidth]{filename.jpg} to make it slightly narrower and leave a small margin on each side.

Can I crop a photo in LaTeX without editing the file?

Yes, use the trim and clip options: \includegraphics[width=4cm, trim=1cm 2cm 1cm 2cm, clip]{filename.jpg}. The four numbers are the amounts to remove from the left, bottom, right, and top edges. This is useful when you want to remove part of a photo without opening an image editor.