Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make the "Figure XX:" text bold and the description text regular font in a bookdown::html_document2?

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
like image 316
Patrick Avatar asked Dec 14 '25 03:12

Patrick


1 Answers

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>: ')"

out 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

like image 57
Tim G Avatar answered Dec 15 '25 15:12

Tim G



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!