重建數據:
x <- structure(list(X = structure(c(1L, 2L, 4L, 3L, 5L), .Label = c("(Intercept)",
"SEXFemale", "SEXFemale:ASIAN", "SEXFemale:BLACK", "SEXFemale:HISPANIC"
), class = "factor"), B.1 = structure(c(3L, 2L, 1L, 1L, 1L), .Label = c("",
"-0.46 (0.023)", "-1.669 (0.093)"), class = "factor"), B.2 = structure(c(3L,
2L, 1L, 1L, 1L), .Label = c("", "-0.386 (0.04)", "-1.701 (0.094)"
), class = "factor"), B.3 = structure(c(4L, 3L, 5L, 1L, 2L), .Label = c("-0.063 (0.089)",
"-0.128 (0.074)", "-0.274 (0.17)", "-1.774 (0.121)", "0.132 (0.163)"
), class = "factor")), .Names = c("X", "B.1", "B.2", "B.3"), class = "data.frame", row.names = c(NA,
-5L))
正則表達式:
x$X <- gsub("SEXFemale:", "\\\\phantom{Female} X ", x$X)
x$X <- gsub("SEXFemale", "Female", x$X)
library(xtable)
xx <- print(xtable(x), print.results = FALSE, include.rownames = FALSE,
sanitize.text.function=function(x)x)
cat(xx)
所得到的文本:
% latex table generated in R 2.15.0 by xtable 1.7-0 package
% Thu Jul 26 17:10:05 2012
\begin{table}[ht]
\begin{center}
\begin{tabular}{llll}
\hline
X & B.1 & B.2 & B.3 \\
\hline
(Intercept) & -1.669 (0.093) & -1.701 (0.094) & -1.774 (0.121) \\
Female & -0.46 (0.023) & -0.386 (0.04) & -0.274 (0.17) \\
\phantom{Female} X BLACK & & & 0.132 (0.163) \\
\phantom{Female} X ASIAN & & & -0.063 (0.089) \\
\phantom{Female} X HISPANIC & & & -0.128 (0.074) \\
\hline
\end{tabular}
\end{center}
\end{table}
以及最終輸出:
你應該問這對http://tex.stackexchange.com/代替 – Giel 2012-07-25 08:37:31
這是可能的'print.xtable(...,print.results = FALSE)'然後使用正則表達式來查找第二列並插入你的'\ phantom {}'調用。我現在要跑,但我可能會在稍後發佈解決方案。 – 2012-07-25 09:15:07
希望羅馬。提前致謝。 – user702432 2012-07-25 09:17:52