问题
如何在上面包装标题(由add_header_above()
插入)?
There is a simple way对一个分层标题执行此操作,但在有第二个(或第三个)标题时不起作用。
可重复的示例
library(kableExtra)
names(iris) <- c("L", "W", "L", "W", " ")
iris[1:2, ] %>%
kable("latex") %>%
add_header_above(
c(
"Sepal is great" = 2,
"Petal is better, (in fac my favorite)" = 2,
"nc" = 1)
) %>%
column_spec(2:ncol(iris), width = "0.3in")
当前输出看起来
R代码的预期输出(大致)
答案 0 :(得分:1)
正如我在Best Practice for newline in LaTeX table中所说,如果你需要在所有kableExtra函数中使用换行符,只需使用\n
。否则,您可以试用linebreak
函数。
library(kableExtra)
names(iris) <- c("L", "W", "L", "W", " ")
iris[1:2, ] %>%
kable("latex") %>%
add_header_above(
c(
"Sepal\nis great" = 2,
"Petal is better,\n(in fac my favorite)" = 2,
"nc" = 1)
) %>%
column_spec(2:ncol(iris), width = "0.3in")