For the output of the below Rmd I would like the "Figure XX:" part to be bold and the descriptive text to be in regular font. How can I achieve that?
---
title: "Figure caption things"
output: bookdown::html_document2
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(ggplot2)
library(plotly)
plot <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point()
```
## My first ggplot2 figure
TEXT TEXT TEXT
```{r fig-ggplot, fig.cap = "My super caption for this ggplot figure here!"}
plot
```
TEXT TEXT TEXT
## My second plotly figure
TEXT TEXT TEXT
```{r fig-plotly, fig.cap = "My super caption for this plolty figure here?!"}
ggplotly(plot)
```
TEXT TEXT TEXT
Add a file _bookdown.yml to the same directory of your bookdown file with the following content:
language:
label:
fig: !expr "function(i) paste0('<b>Figure ', i, '</b>: ')"
To quote bookdown chapter 4.5:
If the language of your book is not English, you will need to translate certain English words and phrases into your language, such as the words “Figure” and “Table” when figures/tables are automatically numbered in the HTML output.(...) For example, if you want FIGURE x.x instead of Figure x.x, you can change fig to "FIGURE " (...) or you can pass an R function that takes a figure reference number as the input and returns a string. (e.g., !expr function(i) paste('Figure', i))
We can use this, to wrap the "Figure XX:" in the HTML bold-tag <b>. I had to wrap the whole expression in quotes, because the colon : has it's own meaning within YAML.
This Github Post, which wanted to translate the Figure to Figura helped a lot: https://github.com/rstudio/pagedown/issues/164#issuecomment-586573398
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With