问题描述
我正在使用RMarkdown创建演示文稿,以在幻灯片中显示。话虽这么说,但在将表格显示为幻灯片时遇到了一些麻烦,因为它们的显示方式比我期望的要小。
我的代码如下:
library(kableExtra)
x <- data.frame(a = c("x","y","z"),b = c(1,2,3))
x %>%
kable() %>%
kable_styling("striped",full_width = FALSE) %>%
column_spec(2,bold = TRUE) %>%
row_spec(1,color = "blue",background = "lightblue",bold = TRUE) %>%
row_spec(2,color = "orange",background = "navajowhite",bold = TRUE) %>%
row_spec(3,color = "red",background = "lightsalmon",bold = TRUE)
下面是我将其编织到ioslides时得到的输出的屏幕截图:
我希望扩展这张桌子,以便使其更适合幻灯片中的可用空间,并且比现在更友好。我也想把字幕居中。
解决方法
亲爱的人肯定在旁观者的眼中;-)。可能有助于格式化字体大小并以粗体显示标题。
要扩大表格范围,请在width
中使用col_spec()
参数。
我假设您已经使用降价语法(## subtitle
)创建了字幕。这作为<h3>Subtitle</h3>
包含在HTML输出中。您还可以使用HTML并将其放在rmd文件<center><h3>subtitle</h3></center>
中。 (请注意,kable()
也具有参数caption
)。
x %>%
kable() %>%
kable_styling("striped",full_width = F) %>%
column_spec(2,width = "20em") %>%
row_spec(0,bold = TRUE,font_size = 24) %>%
row_spec(1,color = "blue",background = "lightblue",bold = TRUE) %>%
row_spec(2,color = "orange",background = "navajowhite",bold = TRUE) %>%
row_spec(3,color = "red",background = "lightsalmon",bold = TRUE)