为什么 \graphicspath 不起作用?

为什么 \graphicspath 不起作用?

我在 Rmarkdown 脚本中使用 pdftex 和 texlive 将header.tex文件附加到我的报告中。我尝试使用以下内容.tex

\usepackage[export]{adjustbox}
\usepackage{eso-pic,graphicx,transparent}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} %
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[R]{Relatório emitido pelo SOMA - Sistema de Observação, Monitoramento e Ação}
\fancypagestyle{plain}{\pagestyle{fancy}}
\pagenumbering{gobble}
\graphicspath{{~/somadb/soma-reports/Rmd/}}
\AddToShipoutPictureFG{
\put(0,0){%
\AtStockCenter{%
\makebox[0pt]{%
\centering
  {\transparent{0.8} \includegraphics[width=0.95\paperwidth,height=0.95\paperheight, valign=c, %
keepaspectratio]{test.png}}%
  }
  }
}}

但它给了我错误:

错误:包 pdftex.def 错误:未找到文件“test.png”

我尝试删除它{test.png}并且{~/somadb/soma-reports/Rmd/test.png}效果很好。

test.png我的位于同一文件夹中.tex,仅供参考。

答案1

正如其他人提到的,\graphicspath{{~/somadb/soma-reports/Rmd/}}这里可能不需要使用。我的建议是使用相对路径,例如\graphicspath{{path/to/images/}}。我的建议是删除该\graphicspath{}命令,因为您已经声明图像位于工作目录中;

\usepackage[export]{adjustbox}
\usepackage{eso-pic,graphicx,transparent}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} %
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[R]{Relatório emitido pelo SOMA - Sistema de Observação, Monitoramento e Ação}
\fancypagestyle{plain}{\pagestyle{fancy}}
\pagenumbering{gobble}
\AddToShipoutPictureFG{
\put(0,0){%
\AtStockCenter{%
\makebox[0pt]{%
\centering
  {\transparent{0.8} \includegraphics[width=0.95\paperwidth,height=0.95\paperheight, valign=c, %
keepaspectratio]{test.png}}%
  }
  }
}}

另一种选择是将所有图像放在一个文件夹中,您可以随意命名(例如img/),然后定义\graphicspath{img/}

\usepackage[export]{adjustbox}
\usepackage{eso-pic,graphicx,transparent}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} %
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[R]{Relatório emitido pelo SOMA - Sistema de Observação, Monitoramento e Ação}
\fancypagestyle{plain}{\pagestyle{fancy}}
\pagenumbering{gobble}
\graphicspath{{img/}}
\AddToShipoutPictureFG{
\put(0,0){%
\AtStockCenter{%
\makebox[0pt]{%
\centering
  {\transparent{0.8} \includegraphics[width=0.95\paperwidth,height=0.95\paperheight, valign=c, %
keepaspectratio]{test.png}}%
  }
  }
}}

相关内容