用网格制作复式表格

问题描述 投票:0回答:1

我希望第二个表的格式具有网格,即具有第一个表的格式。我附上一张图片。

第一个表的代码是:

datos1 = c(12 , 8 , 4 , 6, 4 , 2, 3, 2, 1)
datos11 = c(12 , 8 , 4 ,  3, 2, 1, 6, 4 , 2)
datos2 = c(3 , 6 , 12 , 2, 4 , 8, 1, 2, 4)
datos12 = c(3 , 6 , 12 , 1, 2, 4,2, 4 , 8)
datos3 = c(2 , 1 , 4 , 4, 2 , 8, 6, 3, 12)
datos13 = c(2 , 1 , 4 , 6, 3, 12, 4, 2 , 8)
datos4 = c(4 , 2 , 1 , 8, 4 , 2, 12, 6, 3)
datos14 = c(4 , 2 , 1 , 12, 6, 3, 8, 4 , 2)
datos5 = c(1 , 2 , 4 , 2, 4 , 8, 3, 6, 12)
datos15 = c(1 , 2 , 4 , 3, 6, 12, 2, 4 , 8)
datos6 = c(4 , 8 , 12 , 2, 4 , 6, 1, 2, 3)
datos16 = c(4 , 8 , 12 , 1, 2, 3, 2, 4 , 6)
datos7 = c(1 , 2 , 3 , 2, 4 , 6, 4, 8, 12)
datos17 = c(3 , 2 , 1 , 6, 4 , 2, 12, 8, 4)
datos8 = c(1 , 2 , 3 , 4, 8 , 12, 2, 4, 6)
datos18 = c(2 , 1 , 3 , 4, 2 , 6, 8, 4, 12)
datos9 = c(2 , 4 , 6 , 4, 8 , 12, 1, 2, 3)
datos19 = c(6 , 4 , 2 , 12, 8 , 4, 3, 2, 1)
datos10 = c(2 , 4 , 6 , 1, 2, 3, 4, 8 , 12)
datos20 = c(6 , 2 , 4 , 12, 4, 8, 3, 1 , 2)

w9 <- sample(list(datos1, datos2, datos3, datos4, datos5,datos6,datos7,datos8,datos9,datos10,datos11,datos12,datos13,datos14,datos15,datos16,datos17,datos18,datos19,datos20), 1) 
w9 <- unlist(w9)
tabla = cbind (expand.grid (list (Y = c ("[2,4)","[4,6)","[6,8]") ,
X = c ("6","8","9.5" ))), count = w9)
p1<- ftable (xtabs(count ~ Y + X, tabla ))

grid.table(tabla, rows = NULL)

第二个表的代码是:

p1
r grid
1个回答
0
投票

您可以使用 xtable 包:

latex <- print(xtableFtable(p1), floating = FALSE, print.results = FALSE)

writeLines(
  c(
    "\\documentclass[12pt]{standalone}",
    "\\usepackage{caption}",
    "\\begin{document}",
    "\\minipage{\\textwidth}",
    latex,
    "\\captionof{table}{My caption}",
    "\\endminipage",
    "\\end{document}"
  ),
  "myTable.tex"
)

您需要添加一些美元才能将 myTable.tex 编译为 PDF。

我没有检查过,但我认为你可以将某些行灰显。

© www.soinside.com 2019 - 2024. All rights reserved.