您可以在调用之前使用正则表达式将 插入\phantom{}到您的表中:xtable()
重新创建您的数据:
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}
最后的输出:
