Required Packages

How To Insert Image Into Latex

PL
idmbestpractices.ca
7 min read
How To Insert Image Into Latex
How To Insert Image Into Latex

How to Insert Image into LaTeX: A Complete Guide

Inserting graphics is one of the most powerful ways to enrich a LaTeX document, whether you are preparing a scientific paper, a thesis, or a simple presentation slide. This article walks you through every step, from installing the essential packages to positioning images precisely, and it provides clear examples that you can copy‑paste into your own projects. How to insert image into LaTeX is a question that appears repeatedly on forums, Stack Exchange, and documentation sites, because the answer involves a handful of packages, a few syntax rules, and some troubleshooting tricks. By the end, you will be comfortable adding figures, sub‑figures, and even multi‑page graphics without breaking the flow of your document.

Required Packages

The core of any image insertion workflow relies on the graphicx package. It supplies the \includegraphics command, which is the workhorse for loading external files. Add the following line to the preamble of your `.

\usepackage{graphicx}

If you plan to create sub‑figures or manage floating environments, you will also need subcaption (or the older subfig) and float for custom placement options. A typical preamble looks like this:

\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{float}

Tip: Load packages after any document class options that might affect their behavior, and keep the list short to avoid unnecessary dependencies.

Basic Syntax The simplest way to embed an image is to use the \includegraphics command inside a figure environment:

\begin{figure}
  \centering
  \includegraphics[width=\linewidth]{my_picture}
  \caption{My first inserted image}
  \label{fig:first}
\end{figure}

Here, my_picture is the filename (including its extension) located in the same directory as the .tex file or in a specified input folder. That said, the width=\linewidth option scales the image to the width of the text line, preserving the original aspect ratio. If you omit the width argument, LaTeX will use the image’s natural size, which can cause overflow or excessive whitespace.

Scaling and Positioning

Using the graphicx Options

graphicx offers a suite of length modifiers that let you control size precisely:

  • width=5cm – forces the image to be exactly 5 cm wide.
  • height=3in – forces the image to be exactly 3 inches tall.
  • scale=0.8 – scales the image by 80 % of its original dimensions.
  • keepaspectratio=true – maintains the original proportion when only one dimension is set.

A common pattern is to combine scale with keepaspectratio to avoid distortion:

\includegraphics[scale=0.9, keepaspectratio]{chart.png}

Floating Versus Fixed Placement

By default, LaTeX treats a figure as a float, meaning it may move to the top or bottom of a page, or even to a separate page, to satisfy layout constraints. If you need stricter control, load the float package and use the [H] placement specifier:

\begin{figure}[H]
  \centering
  \includegraphics{diagram.pdf}
  \caption{Non‑floatable figure}
\end{figure}

[H] tells LaTeX to place the figure here, i.In practice, e. , at the exact spot in the source code. Use it sparingly, as over‑floating can lead to awkward page breaks.

Advanced Techniques

Including Multiple Images

When you need to display several related graphics together, the subcaption package shines. It lets you create a grid of sub‑figures, each with its own caption and label, while sharing a common parent caption:

\begin{figure}
  \centering
  \begin{subfigure}[b]{0.3\textwidth}
    \includegraphics[width=\linewidth]{plot1.png}
    \caption{Plot 1}
    \label{fig:plot1}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.3\textwidth}
    \includegraphics[width=\linewidth]{plot2.png}
    \caption{Plot 2}
    \label{fig:plot2}
  \end{subfigure}
  \caption{Comparison of experimental results}
  \label{fig:comparison}
\end{figure}

The [b] option aligns the sub‑captions at the bottom of each sub‑figure, ensuring a tidy layout.

Adding Captions and Labels

Captions provide context and are essential for cross‑referencing. Here's the thing — example: ```latex \begin{figure} \centering \includegraphics[width=0. But use \label immediately after \caption to create a unique identifier that can be referenced with \ref or \cref (from the cleveref package). 6\textwidth]{heatmap.

As shown in \cref{fig:heatmap}, the model predicts...

Want to learn more? We recommend zebras white with black stripes or black with white stripes and x 3 x 2 0 for further reading.


### Including Graphics from Subdirectories  

If you organize images in separate folders (e.In practice, g. Consider this: , `figures/`), you can still include them without moving the files. Simply specify the relative path:  ```latex
\includegraphics[width=\linewidth]{figures/schematic.

Alternatively, use the `graphicspath` directive in the preamble to define a search path:  

```latex
\graphicspath{{figures/}}

Now any file inside figures/ can be referenced by its base name only.

Troubleshooting Common Errors

Error Likely Cause Fix
File myfigure

Completing the Troubleshooting Table

Error Likely Cause Fix
File 'myfigure.pdf' not found. The image file resides outside the directory LaTeX is scanning. So naturally, Place the file in the same folder as the . tex source or add its location with \graphicspath{{../images/}}.
LaTeX Error: File 'myfigure.This leads to pdf' not found. (repeated) The extension is misspelled or the file was never generated. Verify the exact filename (including case) and run the external graphics program again.
Package graphicx Error: Unknown option 'width='. Which means An outdated version of graphicx does not recognise the key‑value syntax. Upgrade the package (e.g., tlmgr update graphicx) or replace width=\linewidth with the older \resizebox{\linewidth}{!}{…}.
Package hyperref Warning: Token not allowed in a PDF string (Unicode) (hyperref)} A non‑ASCII character appears in a label or caption that hyperref tries to embed. Enclose the offending text with \detokenize{…} or use \string to escape special characters.
Package subcaption Warning: \subcaption won't be defined The caption package is loaded before subcaption. Load caption after subcaption, or simply load only subcaption (it re‑exports the needed parts).

Best Practices for Figure Management

  1. Keep file names descriptive and concise.
    A name like thermal_conduction_profile_2024.pdf instantly tells the reader what the graphic depicts, reducing the need for long captions to compensate for ambiguous titles.

  2. Separate source files from compiled PDFs.
    Store original source files (.svg, .eps, .png) in a dedicated folder (e.g., src/) and place the generated PDFs in a figs/ directory. This prevents accidental overwriting when the document is re‑compiled.

  3. Use vector formats for line‑art and schematics.
    PDFs or EPS files retain crisp edges at any scale, which is essential for diagrams, flowcharts, or circuit symbols. Raster images should be reserved for photographs or plots where bitmap detail is unavoidable.

  4. Maintain a consistent caption style.
    Define a custom command in the preamble, such as \newcommand{\mycaption}[2]{\caption[#1]{#2}\label{#2}}, so every caption follows the same formatting rules and can be globally altered later.

  5. Automate repetitive tasks.
    A small shell script or Makefile target can copy newly generated figures into the appropriate directory and trigger pdflatex (or lualatex) with the correct options. Automation reduces human error and speeds up the workflow.


Final Remarks

Effective figure handling in LaTeX blends artistic control with systematic organization. By mastering the core commands, leveraging auxiliary packages, and adopting disciplined file‑management habits, writers can produce documents where visual elements enhance rather than distract from the narrative. The techniques outlined above — from simple inclusion to sophisticated multi‑panel layouts — equip you to present complex data with clarity and professionalism.

Simply put, treat each graphic as a purposeful building block: choose the right format, embed it with the appropriate specifier, caption it thoughtfully, and reference it reliably. When these steps become second nature, the resulting manuscript will not only read smoothly but also look polished, leaving a strong impression on reviewers and readers alike.

The key to truly effective figure management lies in developing habits that make the process seamless over time. That said, once you internalize the workflow—naming files clearly, organizing directories, choosing the right format, and using consistent captioning—the technical details fade into the background, leaving you free to focus on the content itself. Automation, whether through scripts or build tools, further reduces friction, ensuring that updates to figures propagate correctly without manual intervention.

At the end of the day, the goal is to make figures feel like natural extensions of the text rather than afterthoughts. When each image is thoughtfully prepared, properly formatted, and reliably referenced, it reinforces the narrative instead of interrupting it. This attention to detail not only improves readability but also conveys professionalism, making your work more persuasive and easier to engage with. By treating figures as integral components rather than mere decorations, you elevate the entire document, ensuring that both the visual and textual elements work in harmony to communicate your ideas with clarity and impact.

New

Latest Posts

Related

Related Posts

Thank you for reading about How To Insert Image Into Latex. We hope this guide was helpful.

Share This Article

X Facebook WhatsApp
← Back to Home
ID

idmbestpractices

Staff writer at idmbestpractices.ca. We publish practical guides and insights to help you stay informed and make better decisions.