Kableextra 的美学添加 Rmarkdown
Aesthetics of Kable Extra and Rmardown
我正在 R 中复制以下代码来设置我的 table
library(kableExtra)
library(knitr)
item<-c("question1.NATURALES" , "question2.NATURALES" , "question3.NATURALES" , "question4.NATURALES",
"question5.NATURALES" , "question6.NATURALES" , "question7.NATURALES" , "question8.NATURALES" ,
"question9.NATURALES" ,"question10.NATURALES")
key<-c("C", "A", "A", "C", "B", "D", "B", "A", "D", "C" )
A<-c(0 ,3 ,0, 1, 0, 0 ,0 ,0, 2 ,0)
B<-c(0, 0, 1 ,0, 3, 0, 3, 1, 0, 1 )
fa<-data.frame("item"=item,"key"=key, "A"=A,"B"=B)
fa %>%
kbl(escape = FALSE,booktabs = TRUE,longtable=TRUE) %>%
kable_styling(fixed_thead = T,repeat_header_text = "continuaci\'on",
repeat_header_continued="contin\'ua en la siguiente p\'agina") %>%
kable_paper(c("striped","condensed","scale_down","repeat_header"),
full_width = FALSE)
tmp<- data.frame(t(
data.frame(t(select(fa, -item, -key))) %>%
mutate_all(function(i) cell_spec(i, color = ifelse(i == max(i), "green", "red")))
), row.names = NULL)
cbind(fa[1],fa[ 2], tmp) %>%
kbl(escape = FALSE,booktabs = TRUE,longtable=TRUE) %>%
kable_styling(fixed_thead = T,repeat_header_text = "continuaci\'on",
repeat_header_continued="contin\'ua en la siguiente p\'agina") %>%
kable_paper(c("striped","condensed","scale_down","repeat_header"),
full_width = FALSE)
但是打印pdf时结果如下
它不显示样式化或显示页面更改的文字,但如果我 运行 在控制台中显示它,我会得到以下内容
我想知道发生了什么,因为在 pdf 中它以不太美观的方式向我展示。
当然,如果您有任何其他建议,欢迎提出。
我尝试使用 Rmarkdown 打印您的 table。我发现我们可以通过在 kable_styling()
函数中使用 latex_options = "striped"
来获得 PDF 中的条纹样式。
library(tidyverse)
library(kableExtra)
library(knitr)
item<-c("question1.NATURALES" , "question2.NATURALES" , "question3.NATURALES" , "question4.NATURALES",
"question5.NATURALES" , "question6.NATURALES" , "question7.NATURALES" , "question8.NATURALES" ,
"question9.NATURALES" ,"question10.NATURALES")
key<-c("C", "A", "A", "C", "B", "D", "B", "A", "D", "C" )
A<-c(0 ,3 ,0, 1, 0, 0 ,0 ,0, 2 ,0)
B<-c(0, 0, 1 ,0, 3, 0, 3, 1, 0, 1 )
fa<-data.frame("item"=item,"key"=key, "A"=A,"B"=B)
fa %>%
kbl(escape = FALSE,booktabs = TRUE,longtable=TRUE) %>%
kable_styling(fixed_thead = T,
repeat_header_text = "continuaci\'on",
repeat_header_continued="contin\'ua en la siguiente p\'agina",
latex_options = "striped") %>%
kable_paper(c("striped","condensed","scale_down","repeat_header"),
full_width = FALSE)
tmp<- data.frame(t(
data.frame(t(select(fa, -item, -key))) %>%
mutate_all(function(i) cell_spec(i, color = ifelse(i == max(i), "green", "red")))
), row.names = NULL)
cbind(fa[1],fa[ 2], tmp) %>%
kbl(escape = FALSE,booktabs = TRUE,longtable=TRUE) %>%
kable_styling(fixed_thead = T,
repeat_header_text = "continuaci\'on",
repeat_header_continued="contin\'ua en la siguiente p\'agina",
latex_options = "striped") %>%
kable_paper(c("striped","condensed","scale_down","repeat_header"),
full_width = FALSE)
该代码在 PDF 中生成以下两个 table:
我正在 R 中复制以下代码来设置我的 table
library(kableExtra)
library(knitr)
item<-c("question1.NATURALES" , "question2.NATURALES" , "question3.NATURALES" , "question4.NATURALES",
"question5.NATURALES" , "question6.NATURALES" , "question7.NATURALES" , "question8.NATURALES" ,
"question9.NATURALES" ,"question10.NATURALES")
key<-c("C", "A", "A", "C", "B", "D", "B", "A", "D", "C" )
A<-c(0 ,3 ,0, 1, 0, 0 ,0 ,0, 2 ,0)
B<-c(0, 0, 1 ,0, 3, 0, 3, 1, 0, 1 )
fa<-data.frame("item"=item,"key"=key, "A"=A,"B"=B)
fa %>%
kbl(escape = FALSE,booktabs = TRUE,longtable=TRUE) %>%
kable_styling(fixed_thead = T,repeat_header_text = "continuaci\'on",
repeat_header_continued="contin\'ua en la siguiente p\'agina") %>%
kable_paper(c("striped","condensed","scale_down","repeat_header"),
full_width = FALSE)
tmp<- data.frame(t(
data.frame(t(select(fa, -item, -key))) %>%
mutate_all(function(i) cell_spec(i, color = ifelse(i == max(i), "green", "red")))
), row.names = NULL)
cbind(fa[1],fa[ 2], tmp) %>%
kbl(escape = FALSE,booktabs = TRUE,longtable=TRUE) %>%
kable_styling(fixed_thead = T,repeat_header_text = "continuaci\'on",
repeat_header_continued="contin\'ua en la siguiente p\'agina") %>%
kable_paper(c("striped","condensed","scale_down","repeat_header"),
full_width = FALSE)
但是打印pdf时结果如下
它不显示样式化或显示页面更改的文字,但如果我 运行 在控制台中显示它,我会得到以下内容
我想知道发生了什么,因为在 pdf 中它以不太美观的方式向我展示。
当然,如果您有任何其他建议,欢迎提出。
我尝试使用 Rmarkdown 打印您的 table。我发现我们可以通过在 kable_styling()
函数中使用 latex_options = "striped"
来获得 PDF 中的条纹样式。
library(tidyverse)
library(kableExtra)
library(knitr)
item<-c("question1.NATURALES" , "question2.NATURALES" , "question3.NATURALES" , "question4.NATURALES",
"question5.NATURALES" , "question6.NATURALES" , "question7.NATURALES" , "question8.NATURALES" ,
"question9.NATURALES" ,"question10.NATURALES")
key<-c("C", "A", "A", "C", "B", "D", "B", "A", "D", "C" )
A<-c(0 ,3 ,0, 1, 0, 0 ,0 ,0, 2 ,0)
B<-c(0, 0, 1 ,0, 3, 0, 3, 1, 0, 1 )
fa<-data.frame("item"=item,"key"=key, "A"=A,"B"=B)
fa %>%
kbl(escape = FALSE,booktabs = TRUE,longtable=TRUE) %>%
kable_styling(fixed_thead = T,
repeat_header_text = "continuaci\'on",
repeat_header_continued="contin\'ua en la siguiente p\'agina",
latex_options = "striped") %>%
kable_paper(c("striped","condensed","scale_down","repeat_header"),
full_width = FALSE)
tmp<- data.frame(t(
data.frame(t(select(fa, -item, -key))) %>%
mutate_all(function(i) cell_spec(i, color = ifelse(i == max(i), "green", "red")))
), row.names = NULL)
cbind(fa[1],fa[ 2], tmp) %>%
kbl(escape = FALSE,booktabs = TRUE,longtable=TRUE) %>%
kable_styling(fixed_thead = T,
repeat_header_text = "continuaci\'on",
repeat_header_continued="contin\'ua en la siguiente p\'agina",
latex_options = "striped") %>%
kable_paper(c("striped","condensed","scale_down","repeat_header"),
full_width = FALSE)
该代码在 PDF 中生成以下两个 table: