幫助將圖像包含在帶有 tikz 的子資料夾中,\includegraphics 不起作用

幫助將圖像包含在帶有 tikz 的子資料夾中,\includegraphics 不起作用

我有以下文件組織:Main/figures

在“Main/”中,我有我的 main.tex 文件,在“Main/figures/”中,我有一個 .tikz 檔案和一個包含在 tikz 檔案中的 image.png 映像。

tikz 檔案中寫入的路徑是自動產生的,它指向本機資料夾,但是當我從主資料夾載入 tikz 檔案時,它無法找到 png 映像,因為它嘗試在本地搜尋。

我可以透過將路徑設為“figures/image.png”而不是“image.png”來修復此錯誤,但我想避免這樣做,因為理想情況下,我希望外部人員在沒有進一步了解的情況下使用這些文件如何安排它們。

最小的例子:

主文件

\documentclass[english]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{figure}
\input{figures/tikzfile.tikz}
\end{figure}
\end{document}

tikz檔.tikz

\begin{tikzpicture}
\begin{axis}[width=5cm,height=5cm]
\addplot graphics [includegraphics cmd=\pgfimage,xmin=0, xmax=1, ymin=0, ymax=1]
 {image.png};
\end{axis}
\end{tikzpicture}

錯誤

(有幾個無意義的錯誤,例如“缺少$插入”。有一個警告“定義圖像“pgflastimage”時未找到檔案“image.png”。嘗試了“.pdf:.jpg:.jpeg:.png: 」中的所有副檔名: ”)

我想避免的手工修復

將 tikzfile.tikz 中的 {image.png} 修改為 {figures/image.png}。

嘗試過的方法

我在 SE 中發現使用 \graphicspath 作為搜尋圖形的替代方法,但它在我的情況下不起作用。

這裡他們有類似的問題來包含 table.dat,建議的更改似乎僅適用於 \addplot 命令中的表。試著修改解 \pgfplotsset{ table/search path={plots/data}, }

從“表格”到“圖形”,不起作用。

相關內容