Plots in beamer slides converted from .md by pandoc are extremely large

二次信任 提交于 2019-12-03 09:30:16

问题


Normal plots generated by R chunks in R markdown files are exactly there when converted to html slides or pdf. However, when they are converted to beamer slides by pandoc -t beamer ex.md -V theme:Warsaw -o beamer.pdf , the plots become extremely large, especially for those generated by par(mfrow=c(n,m)), in which case only a little part of the plot is displayed.

I tried to fix by setting the chunk option dev='pdf', but it doesn't work out.

The plot in html is

The plot in beamer is


回答1:


The development version of pandoc includes some code in the beamer template that should scale images to the width of the slide. That may help in your case.

You don't need to install development pandoc to use this, since the change is just to a template. Just generate a copy of the default beamer template using pandoc -D beamer > my.beamer. Insert the following lines into my.beamer after the line \usepackage{graphicx}:

\makeatletter
\def\ScaleIfNeeded{%
  \ifdim\Gin@nat@width>\linewidth
    \linewidth
  \else
    \Gin@nat@width
  \fi
}
\makeatother
\setkeys{Gin}{width=\ScaleIfNeeded}

Then use pandoc with the option --template=my.beamer.



来源:https://stackoverflow.com/questions/13004001/plots-in-beamer-slides-converted-from-md-by-pandoc-are-extremely-large

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!