I am trying to render a Quarto document to Word and running into issues with images being rescaled down to ~6 inches. I would prefer if the images filled the available page space.
I found this stack overflow post (Figure sizes with pandoc conversion from markdown to docx) that seems to provide a solution when working with Rmarkdown, but the first answer doesn't work with Quarto (I haven't tried the others as they seem more complicated than I want to deal with right now). Example code below demonstrates this. If you render to Word and right click any of the images where I changed the width and go to "Size and Position" you can see that the image has been scaled. Of course, I can manually change the scaling but that kind of defeats the purpose of using Quarto in the first place.
I'm also using a custom lua filter from this post (Changing page orientation in word using Quarto?) to allow me to specify that certain pages of the document should be in landscape, hence the filters: -docx-landscape.lua
argument in the YAML. I've included that .lua code as well, just in case any potential solution may need to take that into consideration. The .lua file just needs to be in the same directory as the .qmd file.
---
title: "Untitled"
format: docx
editor: visual
project:
execute-dir: project
execute:
echo: false
warning: false
filters:
- docx-landscape.lua
---
```{r}
library(ggplot2)
library(patchwork)
myplot1 <- ggplot(mtcars, aes(mpg, wt)) +
geom_point()
myplot2 <- ggplot(mtcars, aes(mpg, cyl)) +
geom_point()
```
```{r}
myplot1 + myplot2
```
```{r}
#| fig-width: 10
myplot1 + myplot2
```
```{r}
#| fig-width: 15
myplot1 + myplot2
```
::: landscape
```{r}
myplot1 + myplot2
```
```{r}
#| fig-width: 5
myplot1 + myplot2
```
```{r}
#| fig-width: 10
myplot1 + myplot2
```
:::
Lua filter:
local ooxml = function (s)
return pandoc.RawBlock('openxml', s)
end
local end_portrait_section = ooxml
'<w:p><w:pPr><w:sectPr></w:sectPr></w:pPr></w:p>'
local end_landscape_section = ooxml [[
<w:p>
<w:pPr>
<w:sectPr>
<w:pgSz w:h="11906" w:w="16838" w:orient="landscape" />
</w:sectPr>
</w:pPr>
</w:p>
]]
function Div (div)
if div.classes:includes 'landscape' then
div.content:insert(1, end_portrait_section)
div.content:insert(end_landscape_section)
return div
end
end