将两组行规则传递给xtable [英] Pass two set of rules for rows to xtable

查看:76
本文介绍了将两组行规则传递给xtable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下MWE(此 answer 的变体)

Please consider the following MWE (variation from this answer)

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{booktabs}
\usepackage{colortbl, xcolor}

\begin{document}

<<do_table, results = "asis">>=
library(xtable)
mydf <- data.frame(id = 1:10, var1 = rnorm(10), var2 = runif(10))
rws <- c(1,3,5,6,7)
col <- rep("\\rowcolor[gray]{0.95}", length(rws))
print(xtable(mydf), booktabs = TRUE, 
   add.to.row = list(pos = as.list(rws), command = col))
@

\end{document}

为此,我为第1、3、5、6、7行设置了规则.现在让我们说我还要为不同的行(2,4)设置不同的颜色[green].有可能吗?

With this I have set a rule for the rows 1,3,5,6,7. Now let's say I would like also to set a different colour [green] for different rows (2,4). Is it possible?

推荐答案

是的,您只需要构造一个col向量,该向量包含表中每个位置的所有对应颜色.您的示例中有两行颜色不同的行:

Yes, you just need to construct a col vector that contains all corresponding colors for each position in the table. Your example with two differently colored rows:

<<do_table, results = "asis">>=
library(xtable)
mydf <- data.frame(id = 1:10, var1 = rnorm(10), var2 = runif(10))
rws <- c(1,4)
col <- c("\\rowcolor[gray]{0.95}", "\\rowcolor[gray]{0.7}")
print(xtable(mydf), booktabs = TRUE, 
   add.to.row = list(pos = as.list(rws), command = col))
@

这篇关于将两组行规则传递给xtable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆