# Can't find tikz subfiles

I've the following project structure:

./main.tex
./ch1/ch1.tex
./ch1/tikz1/tikz1.tex


The main.tex looks like:

\documentclass{book}
\begin{document}
\subfile{./ch1/ch1.tex}
\end{document}


The ch1.tex looks like:

\documentclass[../main.tex]{subfiles}
\begin{document}
\begin{figure}[H]
\centering
\subfile{./tikz1/tikz1.tex}
\end{figure}
\end{document}


When I run the ch1.tex everything is ok, it finds the tikz1.tex, but when I run the main.tex it can't find the tikz1.tex.

-
Why don't you use standalone package/class? – kiss my armpit Mar 16 '13 at 1:23
DO you need the special tikz?.tex files? Why do you not include them in the chapter file? – Kurt Mar 16 '13 at 1:50
I need them because the tikz code is very big and I don't want to confuse it with ch1.tex code. – Andyk Mar 16 '13 at 1:53
I tried standalone but I got the same problem. Could you please show how to do it correctly? – Andyk Mar 16 '13 at 1:53
The 'standalone' package didn't help because I still need to use 3 different .tex files, so the problem remains. The main.tex can't find the tikz.tex. Please help. – Andyk Mar 16 '13 at 12:57

## 1 Answer

In addition to @MarcoDaniel's observation that \usepackage{subfiles} was missing from the main.tex file, there is a problem with how you compile the documents because of relative paths.

When you compile main.tex, latex looks in <maindir>/ch1/ for ch1.tex and in <maindir>/tikz1/ for tikz1.tex. When you compile ch1.tex (likely from its containing directory <maindir>/ch1/), latex looks in <maindir>/ch1/tikz/ for tikz1.tex. Clearly, both of these cannot be correct, unless you maintain two copies of tikz1.tex which sort of defeats the purpose.

There are a number of ways to solve this:

1. Flatten the directory structure (might be OK depending on number of files)
2. Use absolute paths (not recommended for portability reasons)
3. Input ./ch1/ch1.tex to pdflatex run from <maindir> when compiling ch1.tex on its own. Depending on the editor you use, there may be ways to set this up for files other than the main file.
-