1

I still have problem with sub-figures. I have three images with different pixel size, I need to keep their proportions and sizes with defined widths: 10mm, 20mm and 30mm.

I tried to adapt known answer for my case, but it does not work as I expect. See code below:

---
title: Three images
site: bookdown::bookdown_site
output:
  bookdown::pdf_document2: default
  bookdown::word_document2: default
  bookdown::html_document2: default
header-includes:
  \usepackage{subfig}
---

Below are the figure with 3 sub-figures:

1. hacky way with the table - see  Fig. \@ref(fig:hack);
1. not a hack - see Fig. \@ref(fig:not-hack).

|   |   |   |
| :---: | :---: | :---: |
| ![](img/10mm.png){width=10mm} | ![](img/20mm.jpg){width=20mm} | ![](img/30mm.jpg){width=30mm} |
| (a) | (b) | (c) |

![(\#fig:hack) Three images with different widths – 10 mm (*a*), 20 mm (*b*), 30 mm (*c*)](img/0.png)


```{r not-hack, echo=F, out.width = c("10mm", "20mm", "30mm"), fig.show='hold', fig.cap="Three images with different widths – 10 mm (a), 20 mm (b), 30 mm (c)", fig.subcap=c("", "", ""), fig.align='center'}
par(mfrow=c(1,3))
knitr::include_graphics("img/10mm.png")
knitr::include_graphics("img/20mm.jpg")
knitr::include_graphics("img/30mm.jpg")
```

Below are the results using RStudio 2021.09.0 Build 351 on Ubuntu 18.04 LTS with R 3.4:

PDF - ok HTML - fail DOCX - fail
PDF HTML DOCX
+ size - size + size
+ caption + caption - caption
+ sub-captions - sub-captions - sub-captions

I remember possible related bug, but it is not fixed.

Am I missing something?
Do we have an alternative for knitr::include_graphics to get normal output for all formats - PDF, HTML and DOCX?

N0rbert
  • 559
  • 5
  • 22

0 Answers0