R knitr PDF与\includegraphics有关的问题
使用新的空.rmd文档,此代码可以工作:R knitr PDF与\includegraphics有关的问题,r,graphics,knitr,R,Graphics,Knitr,使用新的空.rmd文档,此代码可以工作: ![](RainbowDolphin.png) \begin{center} \includegraphics[width=4in]{RainbowDolphin.png} \end{center} 但如果没有第一行,它不会: \begin{center} \includegraphics[width=4in]{RainbowDolphin.png} \end{center} 我得到一个错误: ! Undefined control sequence
![](RainbowDolphin.png)
\begin{center}
\includegraphics[width=4in]{RainbowDolphin.png}
\end{center}
但如果没有第一行,它不会:
\begin{center}
\includegraphics[width=4in]{RainbowDolphin.png}
\end{center}
我得到一个错误:
! Undefined control sequence.
l.71 \includegraphics
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" Sampling_03.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output Sampling_03.pdf --template "C:\PROGRA~1\R\R-31~1.2\library\RMARKD~1\rmd\latex\default.tex" --highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in"' had status 43
Execution halted
奇怪。感谢您的帮助 这是因为默认情况下latex模板不加载graphicx包。您可以通过将其添加到yaml标题中手动执行此操作:
---
title: "Untitled"
header-includes: \usepackage{graphicx}
output:
pdf_document:
keep_tex: true
---
您可以通过指定YAML元数据让Pandoc知道您在本文档中有图形:
---
graphics: yes
---
FWIW,这已成为rmarkdown中的默认行为,因此即使您在YAML中没有
图形:yes
:更改也会出现在下一版本的rmarkdown中。