Set the image folder in LaTeX (graphicspath)
\graphicspath{{images/}} in the preamble tells \includegraphics to look for files in the folder images. After that you write \includegraphics{photo.png} instead of \includegraphics{images/photo.png}.
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{graphicx}Write the path in every command
Without \graphicspath, the file name contains the folder. The path is relative to the folder of the main .tex file, also when the command stands in a file loaded with \input. Use forward slashes on Windows too.
\includegraphics[width=0.5\textwidth]{images/image.png}Set one image folder
The folder stands in its own pair of braces inside the argument and ends with /. LaTeX looks in the folder of the document first and then in the folders from \graphicspath.
Complete document:
\documentclass{article}
\usepackage{graphicx}
\graphicspath{{images/}}
\begin{document}
\includegraphics[width=0.5\textwidth]{image.png}
\end{document}Set several folders
Every folder gets its own braces, without commas between them. LaTeX searches the folders in the given order and takes the first file with a matching name.
This goes into the preamble.
\graphicspath{{images/}{plots/}{../shared/logos/}}Pitfalls
\graphicspath{images/}with only one pair of braces does not work: LaTeX then does not find the files and stops with File `imgae' not found.- Current LaTeX versions add a missing
/at the end of a folder name. Older versions do not, so write it. \graphicspathapplies to\includegraphicsonly.\input,\includeand\lstinputlistingdo not use it.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
graphicx - How-to Insert an image in LaTeX
- How-to Split a document into multiple files in LaTeX
- Error File `imgae' not found