添加行或使用print.xtables加粗单个row.names –在行之间添加一些内容? [英] adding rows or boldify single row.names with print.xtables – add something in between rows?

查看:66
本文介绍了添加行或使用print.xtables加粗单个row.names –在行之间添加一些内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用print.xtable add.to.row获取表格式,如下所示:

I try to use print.xtable add.to.row to get table formatted like this:

体育

share of ballers    22.3 
share of skiers      4.6

成瘾

share of smokers    20.3 
share of drinkers    6.6

我的R表确实包含其他row.name,即使这些行不包含任何值.我使用add.to.row选项向不同的行添加颜色,如建议的

My R table does contain the additional row.names even if these rows don't contain any values. I used the add.to.row option to add colors to the different rows like suggested here which worked fine. But what does not work is to add bold text with xtable or add additional hline between the rows. I always get an error message like:

Bad type area settings!检测到的线宽比启发式确定的线宽大52%(类型区域).

Bad type area settings! The detected line width is about 52 % (typearea) larger than the heuristically determined line width.

因此,这可能意味着由于我所做的更改,表对于它的环境而言变得很大了,但是却不知道该怎么做.请注意,我读过这样的帖子 修改xtable输出本身,但是即使对于我来说这可能,我仍在寻找更简单的解决方案.因为如果要使用此解决方案,则必须capture.output并使用regexp替换在两者之间添加一些内容.

So this could mean the table gets to big for its environment because of my changes, but do not have an idea what to do about it. Note I have reads posts like this one that modifies the xtable output itself, but even though this might possible for me to I am looking for an easier solution. Because if I go for this solution I had to capture.output and use regexp replacement to add something in between.

有没有解决的办法?还是有一个更简单的解决方案?

Is there a way around this? Or is there a simpler solution?

推荐答案

有关hline部分,请参见?print.xtable.

hline.after:当为"type="latex""时,是介于-1和 ""nrow(x)""(包括首尾),表示其后的行 水平线应该出现

hline.after: When 'type="latex"', a vector of numbers between -1 and '"nrow(x)"', inclusive, indicating the rows after which a horizontal line should appear

要使您所有的行名都大胆:

To embolden all you rows names:

bold.allrows <- function(x) {
  h <- paste('\\textbf{',x,'}', sep ='')
  h
}
print(xtable(yourTable), 
      sanitize.rownames.function =  bold.allrows)

要加粗一些行名,您可以在这些行中添加特殊标记",例如BOLD:

To embolden some row names, you can add a " special markup" to those rows, e.g. BOLD:

bold.somerows <- 
        function(x) gsub('BOLD(.*)',paste('\\\\textbf{\\1','}'),x)

print(xtable(yourTable), 
      sanitize.rownames.function =  bold.somerows)

例如:

require(xtable)
hh <- head(mtcars)[ , c(1:5)]
## I want to bold 1 and 3 rows 
rownames(hh)[c(1, 3)] <- paste('BOLD', rownames(hh)[c(1, 3)])
print(xtable(hh), sanitize.rownames.function =  bold.somerows)

这篇关于添加行或使用print.xtables加粗单个row.names –在行之间添加一些内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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