I have a problem trying to get my maindocument to compile a subdocument, with an included figure.
I have the following file-structure setup:
mainfile.tex
/chap
/chapter1
/ ch1.tex
/fig
image.pdf
And so my mainfile.tex document has the following preamble:
\documentclass[12pt,a4paper,twoside,final]{memoir}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{subfiles}
\usepackage{graphicx}
\graphicspath{{./chap/chapter1/fig/}}
%
% end preamble
%
\begin{document}
\subfile{./chap/chapter1/ch1}
\end{document}
And in my subfile.tex I have the following setup:
\documentclass[../../main.tex]{subfiles}
\begin{document}
\chapter{ch1}
\includegraphics[scale=0.1]{./fig/image}
\end{document}
Now, when I compile the subfile.tex, the image is rendered nice and fine, but when I try to compile, the mainfile.tex, i get the following error from LaTeX:
LaTeX Error: File '.fig/image' not found
The image in question is a pdf-file which I have stored in a subdirectory inside the directory where the subfile.tex is located, as should be clear from the above structure. I really can't see where it goes wrong? Is it something to do with the order in which the packages are loaded or is it something else entirely?
I really don't get why the above code does not work as intended?
Any help is much appreciated!
Best Answer
I solved it myself by providing the graphicspath arguments with both the paths relative to the subfile and from the mainfile as so:
This way, both the subfile and the mainfile is able to find the correct folder for the figures.