我正尝试使用htmlTable
软件包在Chapter 3 of Reinforced Concrete: A Fundamental Approach by Edward G. Nawy复制第32页的表3.2。
我遇到了按行分布的2组列间距的问题。
这是我的R代码:
install.packages(install.load)
install.load::load_package("data.table", "htmlTable")
# Table 3.2 Approximate mixing water and air content for different slumps
# and Nominal maximum sizes of aggregate
water_nonair <- data.table(V1 = c("1 to 2", "3 to 4", "6 to 7",
"Approximate amount of entrapped air in nonair- entrained concrete (%)"),
V2 = c(350, 385, 410, 3), V3 = c(335, 365, 385, 2.5), V4 = c(315, 340, 360, 2),
V5 = c(300, 325, 340, 1.5), V6 = c(275, 300, 315, 1), V7 = c(260, 285, 300, 0.5),
V8 = c(220, 245, 270, 0.3), V9 = c(190, 210, 0, 0.2))
setnames(water_nonair, c("Slump (in.)", "3/8 in.", "1/2 in.", "3/4 in.",
"1 in.", "1 1/2 in.", "2 in.", "3 in.", "6 in."))
water_air <- data.table(V1 = c("1 to 2", "3 to 4", "6 to 7"), V2 = c(305, 340,
365), V3 = c(295, 325, 345), V4 = c(280, 305, 325), V5 = c(270, 295, 310),
V6 = c(250, 275, 290), V7 = c(240, 265, 290), V8 = c(205, 225, 280),
V9 = c(180, 200, 0))
setnames(water_air, c("Slump (in.)", "3/8 in.", "1/2 in.", "3/4 in.",
"1 in.", "1 1/2 in.", "2 in.", "3 in.", "6 in."))
avg_air_content <- data.table(V1 = c("Recommended average total air content
(percent for level of exposure)", "Mild exposure", "Moderate Exposure",
"Extreme exposure"), V2 = c("", 4.5, 6, 7.5), V3 = c("", 4, 5.5, 7),
V4 = c("", 3.5, 5, 6), V5 = c("", 3, 4.5, 6), V6 = c("", 2.5, 4.5, 5.5),
V7 = c("", 2, 4, 5), V8 = c("", 1.5, 3.5, 4.5), V9 = c("", 1, 3, 4))
setnames(avg_air_content, c("Slump (in.)", "3/8 in.", "1/2 in.", "3/4 in.",
"1 in.", "1 1/2 in.", "2 in.", "3 in.", "6 in."))
结合3 data.tables:
water <- rbind(water_nonair, water_air, avg_air_content)
htmlTable(water, rnames = FALSE, caption = "Table 3.2
Approximate mixing water and air content for different slumps and Nominal
maximum sizes of aggregate", cgroup = rbind(c("", "Water (lb/yd^3
of Concrete for Indicated Nominal Maximum Sizes of Aggregate)", NA),
c("Nonair-Entrained Concrete", "Air Entrained Concrete")),
n.cgroup = rbind(c(1, 2, NA), c(3, 3, 3)), align = "lcc",
tfoot = c("^a These quantities of mixing water are for use in computing cement factors for
trial batches. They are maximal for reasonably well shaped angular coarse aggregates graded
within limits of accepted specifications.", "^b The slump values for concrete containing
aggregate larger than 1 ½ in. are based on slump tests made after removal of particles
larger than 1 ½ in. by wet screening."))
你能提出任何建议吗?
谢谢。
Irucka Embry
答案 0 :(得分:0)
我认为您希望使用tspanner
来分隔堆叠表而不是用于分隔列的cgroup
。
l <- list(water_nonair = water_nonair,
water_air = water_air,
avg_air_content = avg_air_content)
library('htmlTable')
htmlTable(do.call('rbind', l), rnames = FALSE, align = 'lc',
caption = "Table 3.2 Approximate mixing water and air content for
different slumps and Nominal maximum sizes of aggregate",
tspanner = c("Nonair-Entrained Concrete", "Air Entrained Concrete",
'Average Air Content'),
n.tspanner = sapply(l, nrow), n.cgroup = ncol(l[[1]]),
cgroup = "Water (lb/yd<sup>3</sup> of Concrete for Indicated Nominal
Maximum Sizes of Aggregate)",
css.tspanner = "font-style: italic; text-align: center;",
css.tspanner.sep = "")
获取@MaxGordon指出的分数的简单方法是快速gsub
列名称尽管可能更好地设置明确
water <- do.call('rbind', l)
colnames(water) <- gsub('(\\d)/(\\d)', '&frac\\1\\2;', colnames(water))
htmlTable(water, ...)
我不确定^a
和^b
的位置,但您也可以使用html字符作为脚注 - 两个常见的字符:
tfoot = c("<sup>†</sup> 1 in. = 25.4 mm",
"<sup>‡</sup> May be increased by 1 in. for methods
of consolidation other than vibration.")