exams Rnw 文件中图片的位置

location for pic in exams Rnw file

我正在尝试将带有 \includegraphics{pic.png} 的图片添加到来自 exams package.

的 .Rnw 文件的问题中

大致如下:

\begin{question}
What day is today: \includegraphics{picture.png}

\begin{answerlist}
  \item \Sexpr{questions[1]}
  \item \Sexpr{questions[2]}
  \item \Sexpr{questions[3]}
  \item \Sexpr{questions[4]}
\end{answerlist}

\end{question}

运行 exams2pdf 然后

exams2pdf(myexam, n = 1, nsamp = 2, dir = odir, 
                   template = c("my_exam", "solution"), 
                   encoding = 'UTF-8',
                   header = list(
                     Date = "30.05.2017"))

给我:

Error in texi2dvi(out_tex[j], pdf = TRUE, clean = TRUE, quiet = quiet) : 
  Running 'texi2dvi' on 'my_exam1.tex' failed.
LaTeX errors:
! Package pdftex.def Error: File `picture.png' not found.

我几乎尝试了图片可能位于的所有目录,但 tex2dvi / exams2pdf 没有找到 png - 对此有什么建议吗?

考试输出文件(在本例中为 PDF)编译在与当前工作目录不同的目录中。因此,任何补充文件都需要这样标记,以便根据需要复制它们。该软件包为此目的提供了 include_supplement() 函数,并且 exams2pdf("Rlogo") 包含一个有效的示例。在你的情况下,练习 Rnw 应该是:

<<echo=FALSE, results=hide>>=
include_supplement("picture.png")
@

\begin{question}
What does the following logo stand for?

...
\end{question}

如果需要,还请指定 include_supplement("picture.png", dir = "/path/to/files/")

两个进一步的提示:(1) 答案列表也可以生成为

<<echo=FALSE, results=tex>>=
answerlist(questions)
@

这是我们在许多 documentation/examples 之后几年添加的功能,这就是为什么它不那么显眼的原因。 (2) 如果您只有单选题或多选题,您可能会对 exams2nops() 函数感兴趣。这是一种 PDF 输出格式,可以在 R 中自动扫描和评估。

如果您需要进一步的建议,您可以在这里(使用 exams 标签)或在我们的 R-Forge 支持论坛 https://R-Forge.R-project.org/forum/forum.php?forum_id=4377

上提问