繁体   English   中英

如何使用xtable和Sweave在乳胶中打印带括号的符号

[英]How to print symbols with parenthesis in latex using xtable and Sweave

我正在尝试使用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中进行打印,有些提示?

好的,以下对我有用。 您的问题没有说明您是否已加载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}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM