Search code examples
rpowerpointquarto

Change figure width from code chunks in PowerPoint


Figures produced by code chunks are placed to the right of the slide in PowerPoint, and the text is left. This is nice. But I can't modify the figure width. When I try to increase the figure width, the figure height decreases instead. Modifying the figure height works.

I think there must be some box / container created behind the scenes which I don't know how to specifically modify. Any ideas?

---
title: "test"
format: pptx
editor: visual
---

## Test
This is Iris. 

Iris was born in 1936.

Her father's name was Ronald 
```{r}
plot(iris)
```

Default output:

enter image description here

Changing figure width compresses the height

Tried with chunk option fig.width, or YAML option fig-width, here 15 inch. enter image description here

Figure height works

enter image description here


Solution

  • One way is to change the powerpoint template used as described here. I found the description a bit difficult, so let me re-iterate in my own simpleton way.

    1. First, create a template pptx file (e.g., via RStudio terminal):

    quarto pandoc -o template.pptx --print-default-data-file reference.pptx

    This will create a file template.pptx in your working directory.

    1. Second, in this file (template.pptx), change the default layout in the master view.

    Powerpoint menu: view - master - slide master

    For this particular question, you need to change the layout of the "Content with Caption" slide.

    1. Last, but not least, change the YAML header:
    ---
    title: "test"
    format: 
      pptx:
        reference-doc: template.pptx
    editor: visual
    ---
    

    (Needless to say, the file needs to be named like your template file in the working directory).

    Result:

    enter image description here