I am trying to setup a LaTex Project for multiple users. Each user has their own sub-folder inside of each Project sub-folder. I would like each week to be able to also be generated as standalone document. The Problem that I run into is LaTeX does not seem to like relative paths in the sub-folders. What can I do to fix this?

├── example.tex
├── Project1
│   ├── name1
│   │   ├── name1.tex
│   ├── name2
│   │   ├── name2.tex
│   ├── name3
│   │   ├── name3.tex
│   └── week1.tex
├── Project2
│   ├── name1
│   │   ├── name1.tex
│   ├── name2
│   │   ├── name2.tex
│   ├── name3
│   │   ├── name3.tex
│   └── week2.tex
└── Project3
    ├── name1
    │   ├── name1
    ├── name2
    │   ├── name2.tex
    ├── name3
    │   ├── name3.tex
    └── week3.tex

Thanks, Wylie

  • 2
    What do you mean by "not like"? What did you use that "LaTeX did not like"? – Werner May 25 '15 at 19:07
  • I have tried a couple of different ways to use sub directories however it always seems to yield errors at me for ether what I generate a document from example.tex or from one of the Project files like week1.tex. – thewyliestcoyote May 25 '15 at 19:45

Inspired by the link that Timothy provided, I've come up with something slightly different:





% First subfile 

% Second subfile 

% ... etc




    % When compiling main.tex, "\subdir" is already defined; no effect
    % When compiling this file, "\subdir" is defined as "."
    % Either way: paths relative to "\subdir" will be relative to this file's directory

        % Always includes "[project dir]/Project1/name1/Figures/A"

With this approach, the information about how the directories are laid out is only tracked in one file ("main.tex"). Both of the options suggested at Timothy's link instead require that each subfile record its own location, which leaves more files to update if directory structures change (and thus more opportunities for things to get out of sync).

| improve this answer | |
  • 1
    Late to the party, but I found this solution to be excellent. I also added a \newcommand{\maindir}{.} in the main doc's pre-amble, and then use \providecommand{\maindir}{./../../} (if the subfile is two folder in, for example) in the subfile's pre-amble. That way, I can reference folders either relative to the main directory, or sub-directory, if I compile from main or sub. – likethevegetable Nov 26 '19 at 17:51

I found this
which explains the problems of using subfiles package with sub folders and a possible solution in detail.

it basically says, that references made to resources (graphics in particular) must be declared as if the subfile was in the same directory as the main file and must be redirected in the preamble of the subfile.


%redirection for access from actual file location
\let \originalcmd \graphicspath

% resource path from root folder

Timothy Truckle

| improve this answer | |
  • Link only answers are not good. Please add specific details. otherwise, this is likely to be deleted. – luchonacho Oct 15 '16 at 11:04
  • I didn't want to copy that information to avoid issues with copyrights... – Timothy Truckle Oct 15 '16 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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