Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot/image size in exams2nops and in exams2pdf without modifying the template

Tags:

r

r-exams

I have an R/exams exercise like scatterplot.Rmd and tried to include different chunk options into the exams2pdf/exams2nops command, but nothing changed the size of the included image for me:

  • height = 50, width = 50
  • height = 5, width = 5
  • height = 0.5, width = 0.5
  • fig.height = 0.5, fig.width = 0.5
  • out.width = 0.5

Am I doing something wrong?

I saw that I can adapt the LaTeX template but if possible I would avoid it. Is there another way?

like image 740
user301818 Avatar asked Dec 18 '25 15:12

user301818


1 Answers

Main answer: The advice from the other answer you linked applies: How to reduce plot (image) size for `exams2pdf` output?

Short recap:

  • With the chunk options fig.height and fig.width you only control the size of the graphics file which has an influence on the relative size of the annotation etc.
  • The scaling of this graphics file in the PDF document (e.g., 50% or 80% of the text width etc.) may differ from the size of the graphics file, e.g., set via the LaTeX Gin keys.
  • In the default plain.tex template used in exams2pdf() graphics are included with 80% of the text width because the template sets \setkeys{Gin}{width=0.8\textwidth}. You can copy and modify the template if you want to use other options.
  • In exams2nops() no Gin is set so that graphics files are included "as is" (and thus fig.height and fig.width have a direct effect on the relative size as well).

Additional answer: If you want to set a different Gin for the entire document (e.g., 50% of the text width), you can do this in both exams2nops() and exams2pdf() via some LaTeX code passed to the header argument.

exams2pdf("scatterplot.Rmd", header = list(`setkeys{Gin}` = "width=0.5\\textwidth"))
exams2nops("scatterplot.Rmd", header = "\\setkeys{Gin}{width=0.5\\textwidth}")

Note: The list() specification would also work in exams2nops(). The simpler vector specification should also be supported in exams2pdf() in future versions of the package.

like image 116
Achim Zeileis Avatar answered Dec 21 '25 06:12

Achim Zeileis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!