带格式桌的问题带有乳胶格式

问题描述 投票:0回答:1

我有一张桌子,有一张小鼠的桌子,我的物种,年份,总丰度和平均值,如下:

library(tibble)

set.seed(42)  

abundance_sum <- tibble(
  Species = sample(c("Sciurus vulgaris", "Tamias striatus", "Marmota monax", "Sciurus niger", "Glaucomys volans"), 100, replace = TRUE),
  Year = sample(2015:2023, 100, replace = TRUE),
  Total_abundance = round(runif(100, 1, 500), 1),
  n_observations = sample(1:10, 100, replace = TRUE))

print(abundance_sum)

我喜欢桌面的乳胶美学,当我编织降价文件时,它可以工作,但是它太长了,所以我的整个桌子都无法放在一页上。

abundance_sum %>% arrange(Species, Year) %>% select(Year, Total_abundance, n_observations) %>% kbl(format="latex", booktabs = T) %>% kable_styling(latex_options = c("striped", "hold_position")) %>% pack_rows(index = table(abundance_sum$Species), label_row = TRUE) #%>% #save_kable("kable.pdf") # this is what I tried to save my table in latex and get it in pdf format
我试图做一个save_kable,但是当我精确格式=“ latex”时,我不起作用。它给了我这个消息:

Error: LaTeX failed to compile /Users/klervilecorre/Desktop/Stage\ M2/Data/kable.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips.

所以我去了链接,试图调试Tinytex,试图卸载乳胶,然后重新安装它,什么都没有起作用……也许是因为我在Mac上工作?
其他格式(html,简单...)它有效,但我不喜欢表的美学。

有另一种方法可以用像该图像中的桌子这样的美学保存它?

enter image description here 尽管您的代码不可再现,但我确实设法使用

kableExtra
r format save kable kableextra
1个回答
0
投票

从r.
中的

kableExtra
    获取.tex文件
  1. 在主文档中输入表Tex文件。
    使用诸如
    longtable
  2. xltabular
  3. 乳之类的软件包以获取最终的输出。
  4. library(tibble)
    library(kableExtra)
    set.seed(42)  
    
    abundance_sum <- tibble(
      Species = sample(c("Sciurus vulgaris", "Tamias striatus", "Marmota monax", "Sciurus niger", "Glaucomys volans"), 100, replace = TRUE),
      Year = sample(2015:2023, 100, replace = TRUE),
      Total_abundance = round(runif(100, 1, 500), 1),
      n_observations = sample(1:10, 100, replace = TRUE))
    
    
    # use `kableExtra` to generate the tex code
    tbl_df <-
      abundance_sum %>%
      arrange(Species, Year) %>%
      select(Year, Total_abundance, n_observations) %>%
      kbl(format="latex", booktabs = T) %>%
      kable_styling(latex_options = 
                      c("striped", "hold_position")) %>%
      pack_rows(index = table(abundance_sum$Species),
                label_row = TRUE)
    
    # save the table to tex file stored to a folder called `tabs` within your project
    writeLines(tbl_df, "tabs/table_ex.tex")
    
    	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.