【问题标题】:How to print symbols with parenthesis in latex using xtable and Sweave如何使用 xtable 和 Sweave 在乳胶中打印带括号的符号
【发布时间】:2015-02-09 13:09:49
【问题描述】:

我正在尝试使用 xtable 生成一个 tex 表。 在 R 中,该表包含:

>tvPre
        p\\_1              p\\_2                p\\_3
FV     "\\textuparrow M"     ""                 "\\textuparrow R"                
a      "\\textuparrow WH"  ""                 ""                               
b      "\\textuparrow H"   ""                 "\\textuparrow (H)"              
c      "\\textuparrow (WH)"  ""                 "\\textuparrow (H)"              
Oil    "\\textuparrow W"     "\\textuparrow R"  "\\textdownarrow R"  

如果我在控制台中使用标识功能进行消毒,那就没问题了: 指令:

print(xtable(tvPre), rotate.colnames=T,  
      sanitize.text.function = getOption("xtable.sanitize.text.function", function(x)x))

那么,我得到:

 & \begin{sideways} p\_1 \end{sideways} & \begin{sideways} p\_2\end{sideways} & \begin{sideways} p\_3 \end{sideways} \\ 
  \hline
FV & \textuparrow M   &                & \textuparrow R \\ 
a  & \textuparrow WH  &                &   \\ 
b  & \textuparrow H   &                & \textuparrow (H)   \\ 
c  & \textuparrow (WH)  &                & \textuparrow (H) \\ 
O  & \textuparrow W   & \textuparrow R & "\\textdownarrow R" \\

不过,当我将代码放入 Sweave 文件 (.Rnw) 时,我会在 .tex 中获得:

& \begin{sideways} p\_1 \end{sideways} & \begin{sideways} p\_2\end{sideways} & \begin{sideways} p\_3 \end{sideways} \\ 
  \hline
FV & \textuparrow M &  & \textuparrow R \\
a  & \textuparrow W &  &  \\
b  & H              &  & H \\
c  & \textuparrow W &  & H \\
O  & \textuparrow W & \textuparrow R & \textdownarrow R \\

然后,所有括号都消失了,箭头也消失了。我也尝试使用$\\uparrow$,但仍然无法正常工作。 第三行第二列 ("\\textuparrow WH") 打印时没有 "H",但在下一行 " \\textuparrow H" 中仅打印 "H"。 在.tex 文件中,其余带括号的单元格不带箭头也不带括号。

我需要像控制台中打印的那样在 .tex 中打印,有什么线索吗??

【问题讨论】:

标签: r sweave sanitize xtable


【解决方案1】:

好的,以下对我有用。您的问题没有说明您是否已加载 textcomp 包 - 您需要它。同上横向包装。我还将 sanitize.text.function 更改为 sanitize.text.function = function(x){x}

以下脚本保存为 .Rnw 文件。

\documentclass{article}
\usepackage{textcomp}
\usepackage{rotating}

\begin{document}
\SweaveOpts{concordance=TRUE}

<<table, echo=FALSE, results=tex >>= 
require(xtable)

tvPre <- as.data.frame(structure(list(`p\\\\_1` = c("\\textuparrow M", "\\textuparrow WH", 
"\\textuparrow H", "\\textuparrow (WH)", "\\textuparrow W"), 
    `p\\\\_2` = c("", "", "", "", "\\textuparrow R"), `p\\\\_3` = c("\\textuparrow R", 
    "", "\\textuparrow (H)", "\\textuparrow (H)", "\\textdownarrow R"
    )), .Names = c("p\\_1", "p\\_2", "p\\_3"), row.names = c("FV", 
"a", "b", "c", "Oil"), class = "data.frame"))

print(xtable(tvPre), rotate.colnames = TRUE, sanitize.text.function = function(x){x})
@


\end{document}

【讨论】:

  • 行得通!最后,我找不到问题,但我很确定这是工作区之间的同步问题,一种模式正在加载旧代码..我找不到原因,但我重新安装所有并工作。
  • 如何将清理限制在几列?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-14
  • 1970-01-01
  • 1970-01-01
  • 2011-05-25
相关资源
最近更新 更多