首页 > 解决方案 > R to latex:同时清理 % 和 \latexfunction

问题描述

经过一些 R 计算后,我得到了一个如下所示的矩阵:

matrix <- cbind(c(00,01,02),c("some text","random stuff","special characters'"), c("0.12%","\\cellcolor{red!25}3.67%","1.61%"))

我正在尝试将其导出到乳胶,如下所示:

file.name  <-  "file.name"
file.caption  <- "file.caption"
print(xtable(matrix, align = c("l","r","r","r"),
                              label = paste("tab:", file.name, sep = "", collapse = NULL),
                              caption = file.caption),
      type = "latex",
      size="\\normalsize",
      caption.placement = "top",
      # file = paste("graphs/", file.name, ".tex", sep = "", collapse = NULL),
      floating = FALSE,
      tabular.environment = "longtable",
      sanitize.text.function = function(x) x)

如果我不这样做sanitize,pdf 将显示“\cellcolor{red!25}”(显然,我更喜欢让单元格着色)。如果我sanitize因为“%”而无法输入 file.tex。我试过sanitize.text.function = function(x) xsanitize.text.function = identity......没有成功。任何想法?

标签: rlatex

解决方案


推荐阅读