在 latex/sweave 中使用图形路径

Using graphicspath in latex/sweave

我有一个 Sweave 文件,我需要在其中嵌入另一个文件夹中的 png 和 pdf。我就是这样试的

\usepackage{graphicx}
\graphicspath{{inst/extdata/}}
\DeclareGraphicsExtensions{.pdf,.png}
\begin{document}

\begin{figure}
   \includegraphics[scale=0.7]{image.png}
   \caption{captionA}
   \label{fig:labelA}
\end{figure}

我也这样试过,但是没用:

 \graphicspath{{filePath}}

 filePath = "C:/path"

\begin{figure}
   \includegraphics[scale=0.7]{image.png}
   \caption{captionA}
   \label{fig:labelA}
 \end{figure}

我在谷歌上搜索了很多,并查找 https://en.wikibooks.org/wiki/LaTeX/Importing_Graphics#Compiling_with_latex,但这是我得到的错误。

 LaTeX Warning: File `image.png' not found on input
 line 613.

! Package pdftex.def Error: File `image.png' not found.

See the pdftex.def package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.613 ...]{image.png}

我用三种不同的方式来扩展我的评论来实现你的目标;假设你想包含一个名为IMG_7254.JPG的文件图片(注意我在下面的代码中没有写文件扩展名,因为我使用了\DeclareGraphicsExtensions{.JPG}),你可以通过三种方式实现:

  1. 将要编译的文件(.tex之一)和要包含的图像放在同一个文件夹中。 LaTeX 搜索(默认)图片以包含在要编译的文件所在的同一目录中的文档中。在这种情况下,代码只是:

    \includegraphics[width=0.7\textwidth]{IMG_7254}
    
  2. 有图片和文件要编译在非常不同的文件夹中,在这种情况下你必须指定文件的完整路径(可以通过不同的方式找到),例如Mac OS 阅读 here。在这种情况下,代码是:

     \includegraphics[width=0.7\textwidth]{/Users/SabDeM/Pictures/IMG_7254}
    
  3. 将要编译的文件放在一个文件夹中(比如File_to_com),然后将所有要包含的图片放在一个子文件夹中,比如, File_to_com/picturesToInc, 然后指定路径。在后一种情况下,代码是:

    \includegraphics[width=0.7\textwidth]{picturesToInc/IMG_7254}
    

正如您在所有方面(一种或另一种方式)看到的那样,LaTeX(呈现 PDF)必须知道图片在您的计算机中的位置。