Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

What is the right way to include graphics when you are creating a modular document?

My directory structure is as follows:


My main file is report.tex whose content is as follows:

\documentclass[11pt, a4paper, twoside, openright]{book}





The content of file literature.tex is as follows:

\chapter{A review}

\caption{A biological neuron}

Everytime I try to generate a pdf I get an error: File "../../img/biological_neuron" not found. I tried "/img/biological_neuron" instead of "../../img/biological_neuron" but that doesn't work either. One thing that does work is adding \graphicspath{img/} to report.tex. But I don't know if thats the right way to do it. Because even if I do \graphicspath{img/} I have to specify the path for any graphics in an included file as '../../img/biological_neuron' and I think after adding \graphicspath{img/}` we should have to just write '/biological_neuron'. I don't know if this is a bug or am I doing something wrong. Please enlighten. Thank you.

share|improve this question

marked as duplicate by Peter Jansson, Fran, Martin Schröder, Mico, moewe Nov 8 '13 at 19:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

\graphicspath requires it's argument to contain grouped elements. So you should use \graphicspath{{<dir1>}{<dir2>}..}. See section 4.5 Other commands in the graphics package (p 13) of the graphics guide. –  Werner Aug 17 '13 at 5:01
Maybe \graphicspath{{../../img/}} will help? Take note to double braces. –  Eddy_Em Aug 17 '13 at 5:01
@werner: Your solution works. Thank you. But as an aside is this the right way to include graphics from a central location while creating modular documents or is there a better way to manage your directory structure while creating modular documents. For instance having a different directory of graphics for chapters within each chapter folder. I have no idea of the repercussions of any approach. Can you elaborate? –  Shaun Aug 17 '13 at 5:08
@Shaun: It's definitely a good idea. You'll run into problems when you're using similarly-named files across your folder structure though. To that end, you can also define macros for folders. For example, try \def\imgfolder{img/}\includegraphics{\imgfolder myimage}. –  Werner Aug 17 '13 at 5:20

1 Answer 1

One way is to place the images in the same folder, and give the location(s) the \graphicspath{{folder},{folder},...} command.

When using modular documents, especially when the parts are edited by different users idependently, I prefer to use a different method. I usually create an __before.tex and a __after.tex file for each part. Before including any tex files from the folder, I always \input the __before.tex file, and __after.tex file afterwards.

So I have this structure:

----/<part1name> % without numbering
--/* % other folders

I generate these __before.tex and __after.tex files in folders using scripts. In this case, the commands I would put in them is the following:

  • \def\imgfolder{img/partxname} in __before.tex
  • \def\imgfolder\relax in __after.tex

And I use \includegraphics with the \imgfolder location included.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.