首页 > 解决方案 > R中xaringan幻灯片中的表格问题

问题描述

我正在尝试数据集的视觉问题。我在用:

library(tidyverse)
head(starwars) %>% 
  knitr::kable(format = "html")

这是输出:

在此处输入图像描述

这是 YAML 选项:

---
title: "Random Forest presentation"
output:
  xaringan::moon_reader:
    seal: false
    self_contained: true 
    yolo: false
    css: ["css_template/middlebury.css", "css_template/tamu-fonts.css"] 
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
      titleSlideClass: [top, left, inverse]
---

即使在 Rstudio 环境下,表格的显示方式也很奇怪

在此处输入图像描述

我正在使用 CSS 模板,我的表格的 CSS 脚本是这样的:

/* adjust table horizontal spacing */
th, td {
    padding:0 15px 0 15px;
}

/* remove color from tables */
table {
  margin: auto;
  border-top: none;
  border-bottom: none;
}

table thead th { border-bottom: none; }
thead, tfoot, tr:nth-child(even) { background: none; }

这是我的会话信息

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] tools     parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] HSAUR_1.3-9       doParallel_1.0.16 iterators_1.0.12  foreach_1.5.0     caret_6.0-86      lattice_0.20-41  
 [7] forcats_0.5.0     stringr_1.4.0     dplyr_1.0.0       purrr_0.3.4       readr_1.3.1       tidyr_1.1.0      
[13] tibble_3.0.4      ggplot2_3.3.3     tidyverse_1.3.0  

loaded via a namespace (and not attached):
 [1] httr_1.4.2           jsonlite_1.7.1       splines_4.0.2        prodlim_2019.11.13   modelr_0.1.8        
 [6] assertthat_0.2.1     highr_0.8            stats4_4.0.2         blob_1.2.1           cellranger_1.1.0    
[11] yaml_2.2.1           ipred_0.9-9          pillar_1.4.6         backports_1.1.8      glue_1.4.2          
[16] pROC_1.16.2          digest_0.6.27        rvest_0.3.6          colorspace_1.4-1     recipes_0.1.13      
[21] htmltools_0.5.0      Matrix_1.2-18        plyr_1.8.6           xaringan_0.18.1      timeDate_3043.102   
[26] pkgconfig_2.0.3      broom_0.7.6          haven_2.3.1          scales_1.1.1         gower_0.2.2         
[31] lava_1.6.7           generics_0.0.2       ellipsis_0.3.1       withr_2.3.0          nnet_7.3-14         
[36] cli_2.1.0            survival_3.1-12      magrittr_1.5         crayon_1.3.4         readxl_1.3.1        
[41] evaluate_0.14        fs_1.4.2             fansi_0.4.1          nlme_3.1-148         MASS_7.3-51.6       
[46] xml2_1.3.2           class_7.3-17         rsconnect_0.8.16     data.table_1.13.0    hms_0.5.3           
[51] lifecycle_0.2.0      munsell_0.5.0        reprex_0.3.0         compiler_4.0.2       rlang_0.4.8         
[56] grid_4.0.2           rstudioapi_0.11      rmarkdown_2.5        gtable_0.3.0         ModelMetrics_1.2.2.2
[61] codetools_0.2-16     DBI_1.1.0            reshape2_1.4.4       R6_2.4.1             lubridate_1.7.9     
[66] knitr_1.30           stringi_1.4.6        Rcpp_1.0.5           vctrs_0.3.4          rpart_4.1-15        
[71] dbplyr_1.4.4         tidyselect_1.1.0     xfun_0.18 

标签: rknitrkablexaringan

解决方案


推荐阅读