简体   繁体   中英

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

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 在此输入图像描述

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM