使用rmarkdown在pdf中插入GIF [英] Insert GIF in pdf using rmarkdown

查看:799
本文介绍了使用rmarkdown在pdf中插入GIF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用rmarkdown生成HTML和pdf文件.在我的.Rmd文件中,我包含了这样的GIF:

I am using rmarkdown to generate both HTML and pdf file. In my .Rmd file, I included a GIF like this:

![](www/script.gif)

当我将HTML编织成HTML时,效果很好.

When I knit the to HTML it works fine.

rmarkdown::render(documentation_file, encoding="UTF-8")

但是,当我尝试使用编织成PDF时

However, when I try to knit to PDF using

rmarkdown::render(documentation_file, rmarkdown::pdf_document(latex_engine = "xelatex"), encoding="UTF-8")

我有以下问题:

! LaTeX Error: Unknown graphics extension: .gif.

我不介意丢失gif的动画,它的静态版本非常好.

I do not mind to lose the animation of the gif, a static version of it is perfectly fine.

有没有简便的方法可以将GIF动态转换为PDF文档?

Is there any easy way to include/convert on the fly the GIF to my PDF document?

推荐答案

不可能在LaTeX文档中直接包含GIF.

It's not possible to directly include GIFs in a LaTeX document.

在一般的LaTeX中,只有使用latex来编译文档时,才可以包含GIF.使用pdflatexxelatexlualatex时,您需要手动将图形转换为PNG,JPG或PDF.

In general LaTeX, you can only include GIFs if you use latex to compile your document; when using pdflatex, xelatex and lualatex you need to manually convert your figure to e.g. PNG, JPG or PDF.

RMarkdown默认使用pdflatex;虽然您可以通过指定例如来更改LaTeX引擎文档的YAML标头中pdf_document下面的latex_engine: xelatex,无法使用latex进行编译(latex首先会创建一个DVI文件,然后将其转换为PS,然后转换为PS PDF).

RMarkdown by default uses pdflatex; while you may change the LaTeX engine by specifying e.g. latex_engine: xelatex below pdf_document in the YAML header of your document, it is not possible to use latex to compile (latex would first create a DVI file, which is then converted to a PS and then in turn to a PDF).

因此,最简单(也是唯一)的解决方案是将所有GIF图形转换为PNG(或JPG),然后将它们作为图像包含在RMarkdown文档中.

So the easiest (and only) solution would be to convert all GIF figures to PNGs (or JPGs), and then include them as images in your RMarkdown document.

这篇关于使用rmarkdown在pdf中插入GIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆