TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've the following project structure:


The main.tex looks like:


The ch1.tex looks like:


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.

share|improve this question
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

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.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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