How do I get includegraphics to be relative to the current file, when using tikzscale?


Similar to pmav I like to have a .tikz file which contains only the tikzpicture environment. (Main reason beeing, that I am to lazy to wrap all my figures in a full preamble like the standalone class would mandate, and that this is what tikzscale needs as input).

Since I like to use my pictures in different documents my latex folder looks something like this:

-TEST.tex %contains documentclass and loads tikzpreamble,
          % modified by hand to input the tikz file currently under development

While this flow works without fault for pure tikzpictures, I lately had a tikzpicture using \includegraphics. While it was no problem when I worked from inside the pictures folder (TEST.tex), I soon hit the issue that the input path is relative to the main tex file, rather than the current file.

A quick google search led me to the import package with subimport. While this allows me to load the tikzpicture in a way that the includegraphics inside the tikzpicture works, it does not support tikzscale.

I thought I got lucky when I read the following in the tikzscale documentation, in regard to the problem:

If both tikzscale and currfile are loaded, the limitation is fixed, so that both [includegraphics relative to main file AND relative to current file] \includegraphics commands succeed.

However, for me it does not work. I.e. the following results in the png not beeing found:







=> Error message:

Package pdftex.def Error: File `OtherSources/png.png' not found. ...ng.png}

Related: Outsourcing TikZ code

  • 1
    Have you tried setting \graphicspath{}? That might work. If it were me, I'd probably just use sym links.
    – cfr
    Commented Jul 16, 2015 at 1:08
  • @cfr: since I work from both Windows and Linux machines, I am reluctant about using symlinks. Even though modern versions of windows support them, git does not. (There is a comment from April this year, indicating it is still unsupported). As for the graphicspath I did not even know that it exists, so I will try that, however I would love the native feel of just amking all input and co commands relative to the current file.
    – ted
    Commented Jul 16, 2015 at 1:35
  • If I used Windows, I'd be reluctant to do anything ;). I'm just used to doing it so thought I'd mention it. I suspect the directory structure shown in the package documentation's example is significant so that if you want to use the feature, you probably need a similar structure.
    – cfr
    Commented Jul 16, 2015 at 1:47

1 Answer 1


In your example you don't need tikzscale, but if you need it in order to import tikz images with \includegraphics I see two solutions.

One is to patch the \includegraphics using etoolbox to make it compatible with import package. But I'm not competent enough to show you how to do this.

The other one is to use a personal macro myinput to specify the path, and then use this path in the subdocument. Here is your MWE :


\usepackage{tikzscale} % not needed in this example


  \node {\includegraphics{\mypath OtherSources/png.png}};

Note: I'm surprised that you include png inside tikzpicture directly. I modified this by including the image inside a node.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .