0

My main .tex document is located in a "Parent" folder. The "Parent" folder contains several "Chapter" folders: 0_Chapter, 1_Chapter, 2_Chapter, etc. Each "Chapter" folder contains a .tex document (chapter0.tex, chapter1.tex, chapter2.tex), as well as a figure folder (figures0, figures1, figures2, etc), which are included in the main.tex document upon compilation.

As an example, the path for the figures in Chapter 0 is indicated in the chapter0.tex file using \graphicspath{{0_Chapter/figures0/}}, and for Chapter 1, chapter1.tex contains the line \graphicspath{{1_Chapter/figures1/}}.

When I compile the main.tex file, the figures are nicely added to the document. So far, so good.

However, as soon as I do the same for the next Chapter, I get the error message image.png not found.

I tried as well to add a single figure path by adding \graphicspath{{0_Chapter/figures0/}{1_Chapter/figures1/}{2_Chapter/figures2/}} in the main.tex file, however, it only works when including figures from the first two figure directories, and gives an error message for the third one. The only thing that allows calling the figures from the figures2 folder is by adding the directory directly in \includegraphics...:

\begin{figure}[H]
    \includegraphics[width=1\textwidth]{2_Chapter/figures2/image.png}
\end{figure}

I really cannot figure out what the problem is... I tried several methods (some of the links below), but none of them worked... How to add graphics in LaTeX; How to use \graphicspath? ; Multiple graphics directory; \graphicspath and \include;

Does anyone know what the problem might be? Thanks a lot in advance!

EDIT: My files contain the following:

main.tex

 \documentclass[a4paper,11pt,twoside]{report}
\usepackage{graphicx}
\graphicspath{{0_Chapter/figures0/}{figures0/}{1_Chapter/figures1/}{figures1/}{2_Chapter/figures2/}{figures2/}}

        \begin{document}
        \include{0_Chapter/chapter0.tex}
        \include{1_Chapter/chapter1.tex}
        \include{2_Chapter/chapter2.tex}
        \end{document

chapter0.tex

\chapter{Chapter 0}
   Text....
\begin{figure}[H]
    \includegraphics[width=1\textwidth]{image0.png}
\end{figure}

chapter1.tex

\chapter{Chapter 1}
   Text....
\begin{figure}[H]
    \includegraphics[width=1\textwidth]{image1.png}
\end{figure}

chapter2.tex

\chapter{Chapter 2}
   Text....
\begin{figure}[H]
    \includegraphics[width=1\textwidth]{image2.png}
\end{figure}

Actually, everything works nicely, until I try to include figures in chapter2.tex... (text, sectioning, etc from chapter2.tex is included in the main document... only the figures can't be added)

ikoz
  • 1
  • 1
    (1) welcome, (2) In main.tex C1/figures1 makes sense, but inside C1 you need figures1. Have you tried \graphicspath{{0_Chapter/figures0/}{figures0/}{1_Chapter/figures1/}{figures1/}{2_Chapter/figures2/}{figures2/}}? – daleif Jan 05 '17 at 13:45
  • yes i tried using \graphicspath{{0_Chapter/figures0/}{figures0/}{1_Chapter/fig‌​ures1/}{figures1/}{2‌​_Chapter/figures2/}{‌​figures2/}}, however, i get the same error message... – ikoz Jan 05 '17 at 13:57
  • I personally don't see the need to splatter my document and graphics files all over your filesystem. Your problem is one reason why. I suggest strongly to have one image-directory and store all your image files there. Of course, in that case you have to name all your image files uniquely. BTW: you should avoid adding the file name extension to \includegraphics. It makes your document less portable. – Jan Jan 05 '17 at 14:32
  • I agree that having all the figures in one folder and one tex file is much easier... however, as I have loads of figures and long chapters/sections/subsections/subsusections/paragraphs for the thesis, I found it easier to split my chapters in different tex files and merge them at the end... – ikoz Jan 05 '17 at 14:37
  • In this case you are not compiling the chapters on their own. What exactly did you mean by that. Are you sure the folder names are 100% correct in the graphics path list? – daleif Jan 05 '17 at 14:43
  • No, i am not compiling each .tex file individually... i was trying to explain that all my chapters are included in my main.tex file after i compile main.tex. It seems that i wasn't very clear here. And I checked the folder and file names numerous times...they're all correct – ikoz Jan 05 '17 at 14:47
  • It was very confusing. Then you do not need the {figure1} etc. Where exactly is image.png (the one you are saying LaTeX cannot find). Are you 100% sure you spelled that filename correctly? – daleif Jan 05 '17 at 14:49
  • Yes, I am 100% sure when it comes to the spelling. image2.png can't be found and it is located in 2_Chapter/figures2 (image0.png and image1.png in my example are located in 0_Chapter/figures0, and 1_Chapter/figures1, respectively, and they are included in the document). The weird thing is that when I try to include image0.png and image1.png in chapter2.tex, they are "not found" although they appear in chapter 0 and 1 – ikoz Jan 05 '17 at 14:56
  • BTW: you are not showing us your real minimal example. That report document does not support the [H] option. Please make sure your data is 100% correct. And that you actually have files like this on disk. Again this works fine on my system. With the MWE you post here, can we see the .log, update your question with that information. – daleif Jan 05 '17 at 15:12
  • Never use the .tex extension in \include it will break badly. \include{0_Chapter/chapter0} not \include{0_Chapter/chapter0.tex} – David Carlisle Jan 05 '17 at 15:20
  • For some reason removing the .tex extension worked! Thanks a lot!!! – ikoz Jan 05 '17 at 15:27

1 Answers1

1

Too long for a comment. You probably need to tell us more about your setup. This works fine for me.

File structure

ls  -R
.:
C1/  C2/  main.tex

./C1:
figures1/  T1.tex

./C1/figures1:
test1.png

./C2:
figures2/  T2.tex  


./C2/figures2:
test2.png

main.tex:

\documentclass[a4paper]{memoir}
\usepackage{graphicx}
% ignore preamble of included documents
\usepackage{docmute}
\graphicspath{{C1/figures1/}{figures1/}{C2/figures2/}{figures2/}}
\begin{document}

main

\input{C1/T1}

\input{C2/T2}
\end{document}

T1.tex:

\documentclass[a4paper]{memoir}
\usepackage{graphicx}
\graphicspath{{C1/figures1/}{figures1/}{C2/figures2/}{figures2/}}
\begin{document}

\chapter{1}

test1

\includegraphics{test1}
\end{document}

T2.tex:

\documentclass[a4paper]{memoir}
\usepackage{graphicx}
\graphicspath{{C1/figures1/}{figures1/}{C2/figures2/}{figures2/}}
\begin{document}

\chapter{2}

test2

\includegraphics{test2}
\end{document}

So what exactly is different in your setup from my setup.

Note I'm using exactly the same \graphicspath in all files.

daleif
  • 54,450
  • daleif, maybe, the OP has figure-files with identical names in all chapter-directories? Exactly: C1/figures1/test.png and C2/figures2/test.png. This would result in being C1/figures1/test.png included in every chapter. (Having no more information from the OP, I could only guess?) – Jan Jan 05 '17 at 14:28
  • @Jan but then the compilation should resolve because it found something. The OP mentions image not found – daleif Jan 05 '17 at 14:41
  • You are right. Nevertheless, I doubt that creating that lot of directories is a good idea. – Jan Jan 05 '17 at 15:08