Kable Extra和Rmardown的美学

发布于 2025-02-01 13:57:57 字数 1852 浏览 3 评论 0原文

我正在以r为样式的以下代码以样式的表格,


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中,它以不太美学的方式向我展示了我。

当然,如果您还有其他建议,这是欢迎的。

I am reproducing the following code in R to style my 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)

But when printing the pdf the result is as follows

enter image description here

It doesn't show stylized or show the words of the page change but if I run it in the console I get the following

enter image description here

I would like to know what is happening because in the pdf it shows me in a less aesthetic way.

Of course, if you have any other advice, it's welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诺曦 2025-02-08 13:57:57

我尝试使用rmarkDown打印您的桌子。我发现我们可以通过使用latex_options =“条纹”kable_styling()函数中获得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中的以下两个表中产生:

”在此处输入图像说明”

I tried to print your table using Rmarkdown. I found that we can get the striped style in PDF by using latex_options = "striped" in kable_styling() function.

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)

The code results in the following two tables in PDF:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文