无法使用 xtable 格式化数据框

Not able to format dataframe using xtable

我有一个数据框,我想将其显示到 R markdown HTML 文件中。我可以使用 Knitr 的 Kable 函数生成 table,但我想改变外观,比如突出显示 header。正如一些人在 Whosebug 上建议使用 xtable,我尝试这样做。我参考了 Whosebug 并尝试像这样设计我的 outlike。

large <- function(x){
paste0('{\Large{\bfseries ', x, '}}')
}
italic <- function(x){
paste0('{\emph{ ', x, '}}')
}

dat <- Final_Summary_table[1:3, 1:6]

print(xtable(dat), 
sanitize.rownames.function = italic,
sanitize.colnames.function = large,
booktabs = TRUE,
floating = TRUE)

但我得到的不是漂亮的 table,而是我们在记事本上写的东西。

% latex table generated in R 3.3.1 by xtable 1.8-2 package % Mon Nov 14 09:33:01 2016 \begin{table}[ht] \centering \begin{tabular}{rllrrrl} \toprule & {\Large{\bfseries ODS_Tables}} & {\Large{\bfseries AppDS_Tables}} & {\Large{\bfseries ODS_Total_Records}} & {\Large{\bfseries AppDS_Total_Records}} & {\Large{\bfseries Change_in_Count}} & {\Large{\bfseries Results}} \ \midrule {\emph{ 1}} & HCC & tRefHCCCodes & 338.00 & 338.00 & 0.00 & PASS \ {\emph{ 2}} & HCC\_COEFF & tRefHHCCOEFFs & 1166.00 & 794.00 & 372.00 & FAIL \ {\emph{ 3}} & HCC\_HIERARCHY & tRefHHCHierarchies & 337.00 & 253.00 & 84.00 & FAIL \ \bottomrule \end{tabular} \end{table}

请提供任何线索或帮助。

我使用了以下 CSS 格式,它解决了这个问题。

<STYLE TYPE="text/css">
<!--

table {
    width:100%;
}
table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}
th, td {
    padding: 5px;
    text-align: left;
}
table tr:nth-child(even) {
    background-color: #eee;
}
table tr:nth-child(odd) {
   background-color:#fff;
}
table th {
    background-color: black;
    color: white;
}

--->
</STYLE>