R语言 如何将表格和图表文本编辑为粗体

smdncfj3  于 2023-03-27  发布在  其他
关注(0)|答案(1)|浏览(253)

我正在创建一个PDF bookdown文件。但是,我无法编辑表格和图表标题,因此文本“Figure X”和“Table X”以粗体显示。例如,

表1我的第一个表
图2我的第二个图

下面是我运行的代码,使用starwars数据集进行了修改:

---
title: "Untitled"
output:
  bookdown::pdf_document2: default
date: "2023-03-22"
header-includes:
   - \usepackage[singlelinecheck=false]{caption}
toc: FALSE
---

```{r tab2, echo=FALSE, message=FALSE}
library(dplyr)
library(kableExtra)
sw <- starwars[, c("name", "height", "mass", "films")]
kable(sw, "latex", booktabs = TRUE, longtable = TRUE, linesep = "", caption = "Some chars", align = "l") %>%
  kable_styling(latex_options = c("hold_position", "repeat_header"), position="left") %>% 
  column_spec(4, width = "8cm") %>% 
  row_spec(0,bold=TRUE)

你能提供建议吗?
谢谢,马克
rryofs0p

rryofs0p1#

您可以使用{caption}包中的labelfont=bf选项:

---
output:
  bookdown::pdf_document2: default
header-includes:
   - \usepackage[singlelinecheck=false, labelfont=bf]{caption}
---

```{r tab2, echo=FALSE, message=FALSE}
library(dplyr)
library(kableExtra)
sw <- starwars[, c("name", "height", "mass", "films")]
kable(sw, "latex", booktabs = TRUE, longtable = TRUE, linesep = "", caption = "Some chars", align = "l") %>%
  kable_styling(latex_options = c("hold_position", "repeat_header"), position="left") %>% 
  column_spec(4, width = "8cm") %>% 
  row_spec(0,bold=TRUE)

**输出**:

![](https://i.stack.imgur.com/lyCHO.png)

相关问题