在Texstudio中使用graphicx插入圖形失敗

在Texstudio中使用graphicx插入圖形失敗

我使用 Texstudio 和 MikTex 2.9

我想也許是包裹有問題。 MikTex多次告訴我要安裝軟體包,但似乎尚未安裝該軟體包。

我確實將.tex文件和圖表放在同一個資料夾中。

the error says:Package pdftex.def Error: File `../figure1.jpg' not found. ...aphics[width=0.7\linewidth]{../figure1.jpg}

以下是我的程式碼。

\documentclass{article}
\usepackage{graphicx}

\begin{document}
    \begin{figure}
\centering
\includegraphics[width=0.7\linewidth]{figure1}
\caption{}
\label{fig:figure1}
\end{figure}

\end{document}

答案1

該錯誤訊息表示您共享的程式碼不是產生該訊息的程式碼。

在你的例子中,你有

\includegraphics[width=0.7\linewidth]{figure1}

但在產生錯誤的程式碼中,你有

\includegraphics[width=0.7\linewidth]{../figure1.jpg}

這些不一樣。第一個告訴 TeX 在當前目錄中查找figure1,這是一個具有已知擴展名之一的圖像。第二個告訴 TeX 在目前目錄的父目錄中尋找figure1.jpg.如果它位於目前目錄中,它將找不到任何內容。

./figure1

figure1在目前目錄中。

figure1

figure1在目前目錄中。

../figure1

figure1在目前目錄的父目錄中,即目前目錄「上方」的目錄。

答案2

@cfr 是對的。存在著天壤之別。

我無法提供最好的解釋CFR。然而,我可以提供我所遵循的實踐。

考慮下面的圖片

![資料夾結構

我的所有.tex文件.tex folder和圖像都在Images Folder.如果我必須連結到圖像資料夾中的圖像,我使用命令\graphicspath

我只指定路徑一次(之前\begin{document})並在各處按檔案名稱使用影像。

微量元素:

\documentclass{article}
\usepackage{graphicx}

%%%%%Format:- \graphicspath{{path1}{path2}{path3}...}%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\graphicspath{{../ImagesFolder/}}

\begin{document}
    \begin{figure}
    \centering
    \includegraphics[width=0.7\linewidth]{LiLi-USB-Creator}
    \caption{}
    \label{fig:figure1}
    \end{figure}
\end{document}

無論我使用多少圖像或.tex創建多少文件,我都會堅持上述結構。

避免檔案和資料夾名稱中出現空格。 LaTeX 不喜歡您引用的檔案中存在空格。

我在我的設定中嘗試了你的範例 - 進行了一項更改(graphicspath) - 並發現錯誤(無、零、零)。

輸出:

在此輸入影像描述

編譯器:2015年國際紡織展

整合開發環境:紡織工作室

作業系統:烏班圖15.10

編輯:

\graphicspath我已經在 Windows 8、8.1 和10上嘗試過此操作。

謝謝

相關內容