![为什么 Booktabs 在某些情况下不起作用?](https://linux22.com/image/339575/%E4%B8%BA%E4%BB%80%E4%B9%88%20Booktabs%20%E5%9C%A8%E6%9F%90%E4%BA%9B%E6%83%85%E5%86%B5%E4%B8%8B%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8%EF%BC%9F.png)
我正在使用 xtable(R 包)生成一个简单的表格。它运行良好,我想给某些特定的线条上色,所以我添加了相关的包:
\usepackage{booktabs}
\usepackage{colortbl, xcolor}
如果我运行 Rnw 文件直接地代码运行良好,并能根据行的颜色完成工作:)。 但如果我运行 Shiny 应用程序(使用 XeLaTeX),该应用程序通过 knit 执行相同的 Rnw 文件,颜色会意外消失,没有任何通知。我没有将任何数据从 Shiny 应用程序传输到 Rnw 文件,确切的 Rnw 代码保持不变,但颜色不合适,我觉得很奇怪。
我已经比较了生成的文本在两种情况下,这些文件都是相同的。
我遗漏了什么?有人能解释一下这个谜团吗?:)
这是我的代码:
\documentclass[english,hebrew]{article}
\usepackage{amssymb}
\usepackage{fontspec}
\setmainfont[Mapping=tex-text]{Frank Ruehl CLM}
\setsansfont[Mapping=tex-text]{Frank Ruehl CLM}
\setmonofont{Frank Ruehl CLM}
\usepackage{url}
\usepackage{tabularx}
\usepackage{array}
\usepackage{booktabs}
\usepackage{colortbl, xcolor}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\frenchspacing
\makeatother
\usepackage{xunicode}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\begin{document}
<<testing-xtable3,results='asis',echo=FALSE,cache=FALSE>>=
library(xtable)
# Just fake data in the dataframe
my_data <- data.frame(call_date = c("2014-10-05", "2014-10-05","2014-10-05"),
days_of_week = c("item 2", "B","F"),
time = c("07:28:52", "07:28:52","07:28:52"),
duration = c("item 4", "D","H"),
cost_per_minute = c("item 4", "D","H"),
dst = c("90545614735", "90545614735","90545614735"))
df_xtable <- xtable(x=my_data,
caption="A table",
label="my_data")
# align should hold ( ncol(df) + 1 ), don't forget the extra column
align(df_xtable) <- "ccccccX" # with vertical lines: "|l|l|X|X|l|X|X|"
# l stands for Left
# r stands for Right
# c stands for Center
rows_gray <- c(0,2)
my_col <- rep("\\rowcolor[gray]{0.95}", length(rows_gray))
print(
df_xtable,
include.rownames = FALSE,
table.placement = "h",
latex.environments = "center", # Center the table to the page
tabular.environment = "tabularx", # tables whose overall width is fixed.
width = "\\textwidth",
booktabs = TRUE,
add.to.row = list(pos = as.list(rows_gray), command = my_col)
)
@
\end{document}
谢谢你们,
吉尔