0
我想將data.frame轉換爲帶有多列的(booktab)乳膠表,但是我無法創建將\toprule
置於表之上的輸出。下面的數據是用來R xtable with multipleolumns and booktabs
dat <- structure(c(841.8, 804.4, 135.1, 106.2, 0.7025, 0.09645, 305.2,
707.1, 449.3, 119.9, 0.7025, 0.09645), .Dim = c(2L, 6L), .Dimnames = list(
c("ev", "smooth"), c("Mean", "SD", "best", "Mean", "SD",
"best")))
> dat
Mean SD best Mean SD best
ev 841.8 135.1 0.70250 305.2 449.3 0.70250
smooth 804.4 106.2 0.09645 707.1 119.9 0.09645
addtorow <- list()
addtorow$pos <- list(-1)
addtorow$command <- '& \\multicolumn{3}{c}{Tab a}& \\multicolumn{3}{c}{Tab b}\\\\'
print(xtable(dat), add.to.row=addtorow, include.colnames=TRUE,booktabs=TRUE)
輸出看起來幾乎是正確的,但\toprule
是在錯誤的位置。
\begin{table}[ht]
\centering
\begin{tabular}{rrrrrrr}
& \multicolumn{3}{c}{In-sample}& \multicolumn{3}{c}{Out-of-sample}\\
\toprule
& Mean & SD & best & Mean & SD & best \\
\midrule
ev & 841.80 & 135.10 & 0.70 & 305.20 & 449.30 & 0.70 \\
smooth & 804.40 & 106.20 & 0.10 & 707.10 & 119.90 & 0.10 \\
\bottomrule
\end{tabular}
\end{table}
更改addtorow$pos<-list(0)
是不是一個答案,因爲它正確地放置在頂部規則,但把下表的列名的多列行。我正在尋找以下輸出:
\begin{table}[ht]
\centering
\begin{tabular}{rrrrrrr}
\toprule
& \multicolumn{3}{c}{In-sample}& \multicolumn{3}{c}{Out-of-sample}\\
& Mean & SD & best & Mean & SD & best \\
\midrule
ev & 841.80 & 135.10 & 0.70 & 305.20 & 449.30 & 0.70 \\
smooth & 804.40 & 106.20 & 0.10 & 707.10 & 119.90 & 0.10 \\
\bottomrule
\end{tabular}
\end{table}
非常感謝您的任何意見。