Documentation Index
Fetch the complete documentation index at: https://resources.latex-cloud-studio.com/llms.txt
Use this file to discover all available pages before exploring further.
To insert an image in LaTeX, load graphicx and use \includegraphics{...}. Then set width, height, scaling, trimming, captions, labels, and placement with the figure environment.
Quick answer: add \usepackage{graphicx} to the preamble, then write \includegraphics[width=0.8\textwidth]{image-file}. Use trim=... , clip to crop whitespace and figure when you need captions and labels.Related topics: Figure positioning | Tabular environment | Package management
Common image tasks
| If you need… | Use |
|---|
| Insert one image | \includegraphics{image} |
| Set width relative to the page | \includegraphics[width=0.7\textwidth]{image} |
| Keep the aspect ratio | \includegraphics[width=5cm,keepaspectratio]{image} |
| Crop whitespace | \includegraphics[trim=1cm 0.5cm 1cm 0.5cm,clip]{image} |
| Add caption and label | wrap the image in \begin{figure}...\end{figure} |
| Put two images side by side | use two \includegraphics commands with widths like 0.45\textwidth |
Quick Start
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[htbp]
\centering
\includegraphics[width=0.7\textwidth]{example-image}
\caption{Example image}
\label{fig:example}
\end{figure}
\end{document}
Basic Image Insertion
Simple Image Include
\documentclass{article}
\usepackage{graphicx}
\begin{document}
% Basic image insertion
\includegraphics{example-image}
% With file extension
\includegraphics{photo.jpg}
% From subfolder
\includegraphics{images/diagram.png}
% With full path (use forward slashes)
\includegraphics{/Users/name/pictures/graph.pdf}
\end{document}
| Compiler | Formats Supported |
|---|
| pdfLaTeX | PDF, PNG, JPG/JPEG |
| XeLaTeX | PDF, PNG, JPG/JPEG, EPS* |
| LuaLaTeX | PDF, PNG, JPG/JPEG, EPS* |
| LaTeX (DVI) | EPS, PS |
*EPS requires additional configuration
Best practices for formats:
- PDF: Vector graphics, diagrams, plots
- PNG: Screenshots, images with transparency
- JPG: Photographs, images without transparency
Scaling Images
Width and Height Control
\documentclass{article}
\usepackage{graphicx}
\begin{document}
% Scale by width
\includegraphics[width=5cm]{image}
\includegraphics[width=0.8\textwidth]{image}
\includegraphics[width=\columnwidth]{image}
% Scale by height
\includegraphics[height=3cm]{image}
\includegraphics[height=0.25\textheight]{image}
% Scale by both (may distort)
\includegraphics[width=5cm,height=3cm]{image}
% Keep aspect ratio with one dimension
\includegraphics[width=5cm,keepaspectratio]{image}
% Scale factor
\includegraphics[scale=0.5]{image} % 50% of original
\includegraphics[scale=1.2]{image} % 120% of original
\end{document}
Common Width References
% Page dimensions
\includegraphics[width=\textwidth]{image} % Full text width
\includegraphics[width=\columnwidth]{image} % Column width
\includegraphics[width=\linewidth]{image} % Current line width
\includegraphics[width=\paperwidth]{image} % Full paper width
% Relative sizes
\includegraphics[width=0.5\textwidth]{image} % Half text width
\includegraphics[width=0.33\columnwidth]{image} % Third of column
% Using calc package
\usepackage{calc}
\includegraphics[width=\textwidth-2cm]{image} % Text width minus 2cm
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]
\centering
\includegraphics[width=0.6\textwidth]{example-image}
\caption{A sample figure with caption}
\label{fig:sample}
\end{figure}
As shown in Figure \ref{fig:sample}, the image demonstrates...
% Alternative with short caption for list of figures
\begin{figure}[h]
\centering
\includegraphics[width=0.5\textwidth]{graph}
\caption[Short caption]{Long descriptive caption that appears below the figure}
\label{fig:graph}
\end{figure}
\end{document}
| Option | Meaning | Priority |
|---|
h | Here (approximately) | Low |
t | Top of page | Medium |
b | Bottom of page | Medium |
p | Page of floats | Low |
H | HERE (exactly)* | Forced |
! | Override LaTeX’s rules | Modifier |
*Requires \usepackage{float}
% Preferred placement order
\begin{figure}[htbp] % Try here, then top, bottom, finally float page
% Force placement
\usepackage{float}
\begin{figure}[H] % Place exactly here
% Override LaTeX's aesthetic rules
\begin{figure}[!h] % Try harder to place here
Multiple Images
Side by Side Images
\documentclass{article}
\usepackage{graphicx}
\begin{document}
% Method 1: Simple side by side
\begin{figure}[h]
\centering
\includegraphics[width=0.45\textwidth]{image1}
\hfill
\includegraphics[width=0.45\textwidth]{image2}
\caption{Two images side by side}
\end{figure}
% Method 2: With individual captions (subcaption package)
\usepackage{subcaption}
\begin{figure}[h]
\centering
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{image1}
\caption{First subcaption}
\label{fig:sub1}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{image2}
\caption{Second subcaption}
\label{fig:sub2}
\end{subfigure}
\caption{Main figure caption}
\label{fig:main}
\end{figure}
\end{document}
Grid of Images
\usepackage{subcaption}
\begin{figure}[h]
\centering
% First row
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{img1}
\caption{Image 1}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{img2}
\caption{Image 2}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{img3}
\caption{Image 3}
\end{subfigure}
% Second row
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{img4}
\caption{Image 4}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{img5}
\caption{Image 5}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{img6}
\caption{Image 6}
\end{subfigure}
\caption{Grid of six images}
\end{figure}
Rotation and Flipping
\documentclass{article}
\usepackage{graphicx}
\begin{document}
% Rotate image
\includegraphics[angle=90]{image} % 90 degrees
\includegraphics[angle=-45]{image} % -45 degrees
\includegraphics[angle=180]{image} % Upside down
% Rotate and scale
\includegraphics[angle=45,width=5cm]{image}
% Origin of rotation
\includegraphics[angle=90,origin=c]{image} % Center (default)
\includegraphics[angle=90,origin=tl]{image} % Top left
\includegraphics[angle=90,origin=br]{image} % Bottom right
% Reflection (negative scaling)
\includegraphics[width=5cm]{image} % Normal
\includegraphics[width=-5cm]{image} % Horizontal flip
\includegraphics[width=5cm,height=-3cm]{image} % Vertical flip
\end{document}
Clipping and Trimming
% Trim: left bottom right top
\includegraphics[trim=1cm 2cm 1cm 2cm,clip]{image}
% Trim and scale
\includegraphics[trim=1cm 1cm 1cm 1cm,clip,width=5cm]{image}
% Viewport (absolute coordinates)
\includegraphics[viewport=20 20 200 200,clip]{image}
% Show only part of image
\includegraphics[trim=0 0 0 50mm,clip,width=\textwidth]{panorama}
Advanced Techniques
Wrapping Text Around Images
\documentclass{article}
\usepackage{graphicx}
\usepackage{wrapfig}
\begin{document}
\begin{wrapfigure}{r}{0.4\textwidth}
\centering
\includegraphics[width=0.38\textwidth]{image}
\caption{A wrapped figure}
\end{wrapfigure}
This text wraps around the figure. The figure is positioned on the
right side of the page, and the text flows around it naturally.
This is useful for smaller images that don't need the full width
of the page. Continue with more text to see the wrapping effect...
% Options: r (right), l (left), i (inner), o (outer)
\begin{wrapfigure}{l}{0.3\textwidth}
\vspace{-20pt} % Adjust vertical position
\centering
\includegraphics[width=0.28\textwidth]{small-image}
\vspace{-20pt}
\caption{Left aligned}
\vspace{-10pt}
\end{wrapfigure}
\end{document}
Image Paths
% Set graphics path
\graphicspath{{images/}{figures/}{../pics/}}
% Now you can use just the filename
\includegraphics{photo} % Searches in all specified paths
% Multiple paths with subdirectories
\graphicspath{
{./images/}
{./figures/photos/}
{./figures/diagrams/}
{../common/images/}
}
Draft Mode
% Show boxes instead of images (faster compilation)
\usepackage[draft]{graphicx}
% Or document-wide
\documentclass[draft]{article}
% Override draft mode for specific image
\includegraphics[draft=false,width=5cm]{important-image}
% Let LaTeX determine format
\DeclareGraphicsExtensions{.pdf,.png,.jpg,.jpeg}
\includegraphics{image} % Finds image.pdf, image.png, etc.
% Force specific format
\includegraphics[ext=.png]{image}
% EPS to PDF conversion (pdfLaTeX)
\usepackage{epstopdf}
\includegraphics{diagram.eps} % Automatically converted
Best Practices
Image guidelines:
- Resolution: Use 300 DPI for print, 96-150 DPI for screen
- File size: Optimize images before including them
- Formats: Use vector (PDF) for diagrams, raster (PNG/JPG) for photos
- Naming: Avoid spaces and special characters in filenames
- Organization: Keep images in a dedicated folder
- Captions: Always include descriptive captions
- References: Label all figures for cross-referencing
Troubleshooting
Common image problems:
- Image not found: Check path and filename (case-sensitive)
- Wrong format: Ensure format is supported by your compiler
- Distorted image: Use only width OR height, not both
- Image too large: Scale relative to
\textwidth
- Bad placement: Use
[htbp] for flexible positioning
- Missing package: Add
\usepackage{graphicx}
Quick Reference
Essential Commands
| Command | Purpose | Example |
|---|
\includegraphics{} | Insert image | \includegraphics{pic} |
width= | Set width | width=5cm |
height= | Set height | height=3cm |
scale= | Scale factor | scale=0.5 |
angle= | Rotate | angle=90 |
\caption{} | Add caption | \caption{Description} |
\label{} | Add reference | \label{fig:name} |
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{filename}
\caption{Descriptive caption}
\label{fig:reference-name}
\end{figure}