gpt4 book ai didi

r - 单击 rmarkdown::beamer_presentation 时突出显示 kable 表的表条目

转载 作者:行者123 更新时间:2023-12-04 13:29:06 25 4
gpt4 key购买 nike

LaTex beamer presentationrmarkdown::beamer_presentation 生成, 有没有办法突出显示 kableExtra 的特定单元格的内容?点击后的表格?
highlights upon clicking
移动电源

---
output:
bookdown::pdf_book:
base_format: rmarkdown::beamer_presentation
latex_engine: xelatex
slide_level: 2
---

```{r}
library(dplyr)
library(kableExtra)
```

## Table
```{r table, echo = FALSE}
my_df <- mtcars[1:4, 1:2]
my_table <- kable(my_df, booktabs = T, caption = "Table caption")
my_table
```

最佳答案

建议的解决方案使用 kableExtrarow_spec/column_spec/cell_spec functionality ,其中几个 LaTex必须加载包(例如,通过 header-includes: ... )。
enter image description here
该解决方案只剩下一件小事:表编号增加。
也就是说,第一帧上的表编号为“1”,第二帧上的表编号为“2”。
为了让事情看起来像添加的颜色是两个框架之间的唯一区别,理想情况下,两个表的编号应该相同。
要根据需要为行/列/单元格着色,另请参阅 rmarkdown cookbook有关如何使用的更多信息 row_spec/column_spec/cell_spec .

---
output:
bookdown::pdf_book:
base_format: rmarkdown::beamer_presentation
latex_engine: xelatex
slide_level: 2
header-includes:
- \usepackage{booktabs}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage{threeparttablex}
- \usepackage[normalem]{ulem}
- \usepackage{makecell}
---

```{r include=FALSE}
library(dplyr)
library(kableExtra)
```

## Table
```{r table, echo = FALSE}
my_df <- mtcars[1:4, 1:2]
my_table <- kable(my_df, booktabs = T, caption = "Table caption")
my_table
```

## Table {.noframenumbering}
<!-- Add "{.noframenumbering}" such that the frame number is the same on both frames -->
```{r table-with-colored-cell, echo = FALSE}
special_cell <- c(rep(F, 3), T)
colors_of_column_with_special_cell <- c(rep("black", 3), "red")

my_table %>%
column_spec(2, strikeout = special_cell, bold = special_cell, color = colors_of_column_with_special_cell)
```

关于r - 单击 rmarkdown::beamer_presentation 时突出显示 kable 表的表条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66292348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com