Adding Images
How to insert, scale, and position images and figures in your LaTeX document using the graphicx package.
To use images in LaTeX, you must load the graphicx package in your preamble. This package provides the powerful \includegraphics command.
\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\begin{document}
\includegraphics{myphoto.jpg}
\end{document}Scaling and Sizing
By default, \includegraphics will insert the image at its exact original resolution, which is often massive and will bleed off the page.
You can control the size by passing optional arguments in square brackets [] before the filename.
% Set exact width
\includegraphics[width=5cm]{myphoto.jpg}
% Scale relative to the page margin (Recommended)
\includegraphics[width=0.8\textwidth]{myphoto.jpg}
% Scale by a percentage of original size
\includegraphics[scale=0.5]{myphoto.jpg}
% Rotate the image 90 degrees
\includegraphics[angle=90, width=5cm]{myphoto.jpg}Using width=0.8\textwidth is the best practice. It ensures the image takes up exactly 80% of the available text width, keeping your margins perfectly aligned regardless of the original image resolution.
The Figure Environment
Like tables, raw images will just appear exactly where you type the code. For professional academic documents, you want your images to "float" to the optimal spot on the page, and you want to give them a caption and a label for cross-referencing.
Wrap your \includegraphics command in a figure environment to achieve this:
\begin{figure}[htbp]
\centering
\includegraphics[width=0.7\textwidth]{diagram.png}
\caption{A diagram showing the system architecture.}
\label{fig:architecture}
\end{figure}Cross-Referencing
Because you added \label{fig:architecture}, you can now reference this image anywhere in your text. LaTeX will automatically update the number if the image order changes.
As shown in Figure \ref{fig:architecture}, the system is...Supported File Formats
When compiling with pdflatex (the standard compiler), you can use the following image formats:
.jpg/.jpeg(Best for photographs).png(Best for screenshots and diagrams).pdf(Best for vector graphics and charts exported from Python/MATLAB)