1

首先,包 kableExtra 确实产生了很棒的表格。我只是有一个额外的要求:

运行此示例时(来自手册)

 iris[1:10, ] %>% select(-Species) %>%
    mutate_if(is.numeric, function(x) {
          cell_spec(x, "latex", bold = T, color = spec_color(x, end = 0.9),
              font_size = spec_font_size(x))
        }) %>%
    kable("latex", escape = F, booktabs = T, linesep = "", align = "c") 

细胞规格

单元格在每一列中格式化。(1) 如何将它们调整到整个表?(2) 还是用户定义的比例?我注意到两者都kableExtra::spec_color使用 kableExtra::cell_specscales::rescale确实需要from参数但未在函数中使用的函数。

下面是可重现的 .Rnw 脚本代码。

\documentclass{article}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor} 
\usepackage{booktabs}
\usepackage{float}
\usepackage{colortbl}

\begin{document}
<<tab10, echo=FALSE, results="as.is">>=
require(knitr)
require(kableExtra)
require(tidyverse)
@
<<tab1, echo=FALSE, results="as.is">>=
require(knitr)
require(kableExtra)
require(tidyverse)
iris[1:10, ] %>% select(-Species) %>%
    mutate_if(is.numeric, function(x) {
          cell_spec(x, "latex", bold = T, color = spec_color(x, end = 0.9),
              font_size = spec_font_size(x))
        }) %>%
    kable("latex", escape = F, booktabs = T, linesep = "", align = "c") 
@


\end{document}
4

1 回答 1

2

好的,使用最新的开发版本,您可以使用scale_fromin spec_color, spec_font_size& spec_angle

library(kableExtra)
library(dplyr)
library(knitr)
iris[1:10, ] %>% 
  select(-Species) %>%
  mutate_if(is.numeric, function(x) {
    cell_spec(x, "latex", bold = T, 
              color = spec_color(x, end = 0.9, scale_from = range(unlist(iris[1:10, ]))),
              font_size = spec_font_size(x, scale_from = range(unlist(iris[1:10, ]))))
  }) %>%
  kable("latex", escape = F, booktabs = T, linesep = "", align = "c") 

在此处输入图像描述

于 2017-12-19T18:02:54.323 回答