Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 enter image description here

The plot in beamer is enter image description here

like image 575
Elaine Avatar asked Oct 22 '12 01:10

Elaine


1 Answers

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.

like image 137
John MacFarlane Avatar answered Oct 16 '22 17:10

John MacFarlane