为什么R函数print.xtableFtable忽略了我的选项?

时间:2016-10-22 16:24:03

标签: r latex output

我有以下代码,print.xtableFtable忽略了latex的其他选项。

##### Contingency tables - 34Y
library(xtable)
B <- ftable(prereg34Y_sub$employmentStatus34Y, prereg34Y_sub$ethnicity34Y, dnn=c("Unemployed", "NonBritish"))
sink("CTFemaleNonBrit34Y.tex", type="output")
print.xtableFtable(xtableFtable(B, method = "compact"), table.placement = "h!")
sink()

输出结果为:

% latex table generated in R 3.3.1 by xtable 1.8-2 package
% Sat Oct 22 18:08:35 2016
\begin{table}[ht]
\centering
\begin{tabular}{l |rr}
\hline
Unemployed $\vert$ NonBritish & \multicolumn{1}{l}{    0} & \multicolumn{1}{l}{    1} \\ 
\hline
0                              & 2065 &   68 \\ 
1                              &   31 &    2 \\ 
\hline
\end{tabular}
\end{table}

表的位置是ht而不是h!。有谁知道为什么?

1 个答案:

答案 0 :(得分:1)

似乎table.placement参数从print.xtableFtable传递到print.xtable,但您可以在运行{{{}}之前设置全局options(xtable.table.placement = "h!")。 1}}

实施例

print(xtableFtable(B))

所以全局设置选项

library(xtable)

# table.placement doesnt seem to work
B <- ftable(mtcars$am, mtcars$cyl, dnn=c("Unemployed", "NonBritish"))
print(xtableFtable(B), table.placement = "h!")     
# % latex table generated in R 3.3.1 by xtable 1.8-2 package
# % Sat Oct 22 18:00:52 2016
# \begin{table}[ht]
# ---
# ---

# But works for other data types
B2 <- table(mtcars$am, mtcars$cyl, dnn=c("Unemployed", "NonBritish"))
print(xtable(B2), table.placement = "h!")
# % latex table generated in R 3.3.1 by xtable 1.8-2 package
# % Sat Oct 22 18:00:52 2016
# \begin{table}[h!]
# ---
# ---