I have the following file organization: Main/figures

in 'Main/' I have my main.tex file, in 'Main/figures/' I have a .tikz file and a image.png image that gets included in the tikz file.

The path written in the tikz file is generated automatically and it points to the local folder, but when I load from the Main folder the tikz file, it fails to find the png image, as it tries to search locally.

I can fix this error by setting the path to "figures/image.png" instead of just "image.png", but I want to avoid doing so, as ideally I would like to external people to use these files without further knowledge on how to arrange them.

Minimal example:





\addplot graphics [includegraphics cmd=\pgfimage,xmin=0, xmax=1, ymin=0, ymax=1]


(there are several nonesense errors like "missing $ inserted." There is a warning "File "image.png" not found when defining image "pgflastimage". Tried all extensions in ".pdf:.jpg:.jpeg:.png:" )

Handmade fix I want to avoid

modify in the tikzfile.tikz: {image.png} to {figures/image.png}.

Attempted methods

I've found in SE the use of \graphicspath as an alternative to search for the figures, but it doesn't works in my case.

Here they have a similar problem to include a table.dat, the suggested change seems to apply just for tables in the \addplot command. Trying to modify the solution \pgfplotsset{ table/search path={plots/data}, }

from "table" to "graphics", doesn't works.

  • 1
    Please provide an example we can compile which will give the error and tell us the exact text of the error message. 'Not working' could mean a number of things. However, I suspect that you are confusing two different ways of including external images: one is supplied by graphicx and the other by pgf. \graphicspath will have no effect on the inclusion of graphics using the PGF mechanism, as far as I know. – cfr Feb 24 '18 at 23:18
  • You could add figures to your input path. If it doesn't exist, it won't hurt anything, but it will cause TeX to search there, as well as everywhere else. Does it not work to use \includegraphics here rather than \pgfimage? – cfr Feb 25 '18 at 21:40
  • That is more or less what I want to achieve, but with \pgfimage. \includegraphics is not really what I want to use. The presented example is a minimal working one with my issue, but I'm actually making heavy use of the capabilities of \pgfimage with tikz. – pancho Feb 28 '18 at 9:40
  • Why? Are you masking images? That's the only good reason I can think of. Other than that, the TikZ manual itself recommends using graphicx instead. Like I said, you can add it to TEXINPUTS regardless. – cfr Feb 28 '18 at 17:29
  • 1
    You can use the texinputs method with \pgfimage. I'd expect you could alternatively do the scaling with \includegraphics - as far as I know, the masking stuff is the main thing \pgfimage has which \includegraphics doesn't. In the latter case, you can either use \graphicspath or you could set texinputs, so you have an additional option for helping TeX find the PNG. Masking can be used if, for example, you want to show an image as if it had holes in it or if you want so create a fading effect, so that the image is more (or less) opaque in some parts than others. You make a black ... – cfr Mar 1 '18 at 17:22

Your Answer

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

Browse other questions tagged or ask your own question.