Figures and images in LaTeX
Use \includegraphics from the graphicx package to insert images into LaTeX documents.
Quick answer
latex
\usepackage{graphicx} % in preamble
\includegraphics[width=0.8\linewidth]{image.png}Basic image insertion
latex
\usepackage{graphicx}
% Image at half the line width:
\includegraphics[width=0.5\linewidth]{photo.jpg}
% Fixed width:
\includegraphics[width=8cm]{diagram.pdf}
% Fixed height (aspect ratio preserved):
\includegraphics[height=5cm]{chart.png}
% Scale relative to original size:
\includegraphics[scale=0.5]{logo.pdf}Figure float with caption
Wrap in a figure environment to add a caption, label, and let LaTeX position it automatically.
latex
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\linewidth]{results.png}
\caption{Experimental results showing accuracy over epochs.}
\label{fig:results}
\end{figure}
% Reference it:
As shown in Figure~\ref{fig:results}, ...Placement options
| Option | Meaning |
|---|---|
| h | Here (approximately) |
| t | Top of the page |
| b | Bottom of the page |
| p | Separate page for floats |
| H | Exactly here (float package required) |
Side-by-side figures
latex
\begin{figure}[htbp]
\centering
\begin{minipage}{0.45\linewidth}
\includegraphics[width=\linewidth]{before.png}
\caption{Before}
\end{minipage}
\hfill
\begin{minipage}{0.45\linewidth}
\includegraphics[width=\linewidth]{after.png}
\caption{After}
\end{minipage}
\end{figure}Image path setup
latex
% Declare a folder so you don't repeat the path:
\graphicspath{{images/}{figures/}}
% Now just use the filename:
\includegraphics[width=\linewidth]{chart.pdf}