Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical Supply Distributor100,000+ medical supplies. 48-hour critical dispatch.Ships from 8 regional U.S. hubs. Net-30 terms for verified institutional accounts.Shop lac.us CodeCASRAIlac.us

Include Graphic in LaTeX: graphicx Image Guide

Learn how to include a graphic in LaTeX with the graphicx package, configure dimensions, preserve aspect ratios, manage folders, and fix common errors.

Written and maintained by CASRAI Editorial Board

Last updated

To include a graphic in LaTeX, load the graphicx package in your document preamble and insert the includegraphics command where the visual should appear. The graphicx package provides key-value controls for dimensions, rotation, trimming, and scaling across PDF, PNG, and JPEG formats in modern TeX engines.

What it is used for in research

Researchers use the graphicx package and its primary command, includegraphics, to embed figures, experimental plots, microscopy captures, and vector schematics directly into LaTeX manuscripts. In academic publishing, visual clarity is critical for presenting data derived from statistical software like R, Python, and MATLAB.

Unlike standard word processors where imported graphics are compressed into proprietary binary containers, LaTeX treats graphic files as external assets referenced during compilation. This separation preserves native vector resolution for publication formats (such as PDF and EPS) and allows authors to adjust figure scaling programmatically across single-column and multi-column journal templates without visual distortion.

Install or access

The graphicx package is part of the standard LaTeX graphics bundle (documented in grfguide by the LaTeX Project Team) and is bundled by default across all modern TeX distributions:

  • TeX Live and MacTeX: Included in the base distribution scheme. No manual installation is needed; declare usepackage{graphicx} in your preamble.
  • MiKTeX: Bundled in standard installations. If an updated graphics package is required, the MiKTeX Console package manager fetches updates automatically from CTAN.
  • Overleaf and Cloud Platforms: Pre-installed across all default compiler images (pdfLaTeX, XeLaTeX, and LuaLaTeX). You can upload image files directly into the project file tree via the Upload icon in the left-hand sidebar or use the Insert Figure toolbar button in the visual editor.

Step-by-step task

Follow these numbered steps to add an image to your manuscript using standard LaTeX commands:

  1. Place the image file in your project directory: Store your graphic file (e.g., plot-results.pdf or diagram.png) in the root folder alongside your .tex document or in a dedicated subfolder such as images/.
  2. Load graphicx in the preamble: Add the package declaration before begin{document}:
    usepackage{graphicx}
  3. (Optional) Define the graphics search path: If your graphics are stored in a subfolder, declare the search path in the preamble using graphicspath:
    graphicspath{{./images/}{./figures/}}

    Note that each directory path must be enclosed within its own set of curly braces and end with a forward slash.

  4. Insert the image command: Place includegraphics at the desired location in your text. Specify the target width relative to page dimensions:
    includegraphics[width=0.85linewidth]{plot-results}

    Omit the file extension in the filename argument. When the extension is omitted, the LaTeX compiler automatically searches for compatible formats matching the active engine.

  5. Wrap in a floating figure environment: For formal research articles, wrap the command inside a LaTeX figure environment to provide automated numbering, a caption, and a cross-referencing label:
    begin{figure}[htbp]
      centering
      includegraphics[width=0.85linewidth]{plot-results}
      caption{Observed response curves across experimental treatment groups.}
      label{fig:results}
    end{figure}
  6. Center and cross-reference: Use centering in LaTeX via the centering declaration rather than a center environment to prevent extra vertical gaps. Reference the figure in your narrative using LaTeX ref syntax: See Figure~ref{fig:results}.

Key-value options for includegraphics

The extended syntax provided by graphicx accepts a comma-separated list of optional arguments inside square brackets. The following parameters are defined in the CTAN grfguide manual:

Option Key Expected Value Function and Practical Behavior
width Dimension (e.g., 0.8linewidth, 10cm) Scales the graphic horizontally to the specified width while adjusting height proportionally unless height is also set.
height Dimension (e.g., 6cm, 3in) Scales the graphic vertically to the specified height.
keepaspectratio Boolean (true or false) Maintains original image aspect ratio when both width and height are specified, scaling the image to fit within the bounding dimensions without distortion.
scale Numerical factor (e.g., 0.75) Scales the image proportionally by the specified multiplier.
angle Degrees (e.g., 90, -90) Rotates the image counter-clockwise by the specified angle.
origin Anchor code (e.g., c, lb, rt) Specifies the rotation anchor point (center, left-bottom, right-top).
trim Four dimensions (left bottom right top) Crops the visible boundary by the specified lengths (e.g., trim=5mm 10mm 5mm 10mm).
clip Boolean (true or flag clip) Enforces bounding-box clipping. Must be declared alongside trim to prevent trimmed margins from bleeding into surrounding text.
draft Boolean (true or flag draft) Suppresses image rendering and outputs an empty rectangular outline with the filename, accelerating document compilation during drafting.
page Integer (e.g., page=2) Selects a specific page number to import when referencing a multi-page PDF document.

Output and how to read it

When compiling a document containing included graphics, the TeX engine produces two distinct outputs: the formatted visual page and the compiler log.

  • Rendered Document: Vector artwork (PDF, EPS) renders cleanly at any zoom level, while raster artwork (PNG, JPEG) displays at its native pixel resolution scaled according to your width or height options. If wrapped in a figure float, the graphic appears alongside an incremented caption number (e.g., “Figure 1:”).
  • Compiler Transcript Log: During compilation, the log indicates successful file loading with bracketed path references, such as [use ./images/plot-results.pdf].
  • Overfull hbox Warnings: If an image is scaled wider than the printable text column (for example, using a fixed width like width=18cm on a standard text column of 14cm), the compiler reports an Overfull hbox (... too wide) warning. The graphic will visibly protrude into the right-hand page margin. Setting width=linewidth ensures the visual adapts automatically to column boundaries.

Troubleshooting

Image compilation issues typically stem from path resolution errors, special characters in filenames, or format incompatibilities:

  • LaTeX Error: File ‘filename’ not found:
    Verify that the image file exists in the specified folder and that the filename matches exactly, including letter case. Linux and cloud build servers are strictly case-sensitive. If you use graphicspath, verify that the path includes double curly braces and a trailing slash: graphicspath{{./figures/}}.
  • Missing $ inserted or syntax error on filename:
    Filenames containing underscore characters (such as data_analysis_plot.png) can trigger math-mode parser errors because the underscore is reserved for math subscripts. Review rules for typing an underscore in LaTeX, rename files using hyphens (e.g., data-analysis-plot.png), or load the underscore package.
  • Image distortion or aspect ratio warping:
    Setting both width and height explicitly forces the image to conform to both measurements regardless of its original shape. Add keepaspectratio to the option list (e.g., [width=linewidth,height=8cm,keepaspectratio]) to preserve the original proportions.
  • Trimmed area still visible:
    The trim option shifts the bounding box coordinates but does not automatically mask artwork outside those bounds. Always include the clip flag (e.g., [trim=10 20 10 20,clip]) to truncate external content.

Free alternatives

While graphicx is the universal standard for inserting pre-rendered files, researchers have several free alternatives and complementary tools for incorporating visual materials into LaTeX papers:

Tool / Package Syntax and Mechanism Best Suited For Limitations
graphicx Key-value macro (includegraphics[options]{file}) Universal insertion of external vector (PDF) and bitmap (PNG, JPG) images. Cannot create or alter graphic contents internally; requires external image generation.
graphics Positional coordinate arguments (includegraphics[llx,lly][urx,ury]{file}) Legacy LaTeX 2.09 compatibility and minimal base installations. Lacks key-value arguments; difficult to specify relative widths like linewidth.
TikZ / PGF Declarative programmatic drawing language Publication-quality schematics, flowcharts, neural network diagrams, and geometric models. Steep syntax learning curve; significantly increases compilation time on complex documents.
pgfplots Direct data-driven plotting macros Generating academic line graphs, scatter plots, and bar charts directly from CSV data files. High memory consumption when plotting large scientific datasets with thousands of observations.
svg package Automated Inkscape bridge (includesvg{file}) Importing Inkscape or web SVG vector files directly without manual export steps. Requires enabling shell escape (-shell-escape) and maintaining an external Inkscape installation.

Frequently asked questions

What image file formats does LaTeX support?

Modern TeX engines (pdfLaTeX, XeLaTeX, and LuaLaTeX) natively support PDF, PNG, and JPEG formats. PDF is recommended for plots and line art because vector elements scale smoothly without rasterization. PNG is ideal for screenshots and digital microscopy, while JPEG is best for photographic plates. EPS files are supported directly in XeLaTeX and are automatically converted to PDF in pdfLaTeX via the epstopdf utility.

Why should I omit the file extension in includegraphics?

Omitting the file extension (for example, writing includegraphics{figure1} rather than includegraphics{figure1.pdf}) enables the compiler to automatically select the most appropriate supported format available in your project directory. This practice allows your document to compile smoothly across different engines, such as switching between pdfLaTeX (which favors PDF/PNG) and legacy dvips (which favors EPS).

How do I center an included graphic?

To center an included graphic inside a floating figure environment, place the centering declaration immediately after begin{figure} and before includegraphics. Avoid wrapping the image in a begin{center}...end{center} environment because the center environment introduces unwanted extra vertical whitespace above and below the graphic.

How do I keep the aspect ratio when setting both width and height?

Pass the keepaspectratio key in the optional argument list alongside your width and height constraints (for example: includegraphics[width=linewidth,height=8cm,keepaspectratio]{plot}). The compiler scales the image to fit within the bounding dimensions without altering its width-to-height ratio.

Sources

  • CTAN. (2026). Packages in the ‘graphics’ bundle (grfguide). Comprehensive TeX Archive Network. Checked 2026-11-07. https://ctan.org/pkg/grfguide
  • Overleaf. (2026). Inserting Images. Overleaf Documentation. Checked 2026-11-07. https://www.overleaf.com/learn/latex/Inserting_Images
  • The LaTeX Project. (2026). LaTeX2e Graphics and Colour. Checked 2026-11-07. https://www.latex-project.org/help/documentation/
  • TeX FAQ. (2026). Importing Graphics into LaTeX Documents. TeX Frequently Asked Questions. Checked 2026-11-07. https://texfaq.org/FAQ-impgraph

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Include Graphic in LaTeX: graphicx Image Guide

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →