使用xtable生成带有重要星号(***)的Latex表 [英] Use xtable to produce a Latex table with significance stars (***)

查看:184
本文介绍了使用xtable生成带有重要星号(***)的Latex表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用xtable从R生成Latex表.它工作正常,但是在其中一个表中,我对某些数字具有显着性.像这样的数据框X:

I am currently using xtable to generate Latex tables from R. It works fine, but in one of the tables I have significance stars to some of the numbers. Something like this dataframe X:

1 2 3 4 5 Test1 Test2 Test3    
a  "1.34" "0.43" "-0.26" "0.13" "0.05" "3.35^{.}"     "343^{***}" "3244^{***}"
b "2.02" "2.17" "-3.19" "4.43" "1.43" "390.1^{***}"  "31.23^{***}"  "24^{***}"
c    "23.07" "32.1"  "24.3"   "3.89" "0.4"  "429.38^{***}" "17.04^{***}"  "2424^{***}" 
d    "21.48" "14.45" "14.19"  "22.04" "0.15" "385.17^{***}" "2424^{***}"  "2424^{***}"

我在星号前使用'^',因为在乳胶意义上,星在该格式下看起来更好.另一个选项是:

I am using '^' before the stars because in Latex significance stars look better in that format. The other option would be:

a  "1.34" "0.43" "-0.26" "0.13" "0.05" "3.35."     "343***" "3244***"
b "2.02" "2.17" "-3.19" "4.43" "1.43" "390.1***"  "31.23^***"  "24***"
# etc.

如果我通过以下方式使用xtable:

If I use xtable via:

  print(xtable(X, label="X"),
  size="normalsize", 
  include.rownames=FALSE, 
  include.colnames=TRUE, 
  caption.placement="top",
  hline.after=NULL
  )

我得到如下输出:

 \begin{table}[ht]
 \centering
{\normalsize
\begin{tabular}{llllllll}

 1 & 2 & 3 & 4 & 5 & Test1 & Test2 & Test3  \\ 
 242 & 123 & -42.3 & 0.43 & 34 & 3.35\verb|^|\{.\} # Hhere is the problem: \verb
 & 242.58\verb|^|\{***\} &   0.06\verb|^|\{***\} \\ # etc. etc.
 \end{tabular}
 }
 \end{table}

这里的问题是添加的\ verb.如果xtable没有添加它,那么该表对我来说很好.所以我的问题是:有没有办法解决?我只想要格式如下的重要星星:

The problem here is the \verb which was added. If xtable didn't add it, the table would be fine for me. So my question is: Is there a way around that? I just want significane stars which are in the format:

^{***} 

在Latex表中,但是已经在R中生成,因此我可以快速生成正确格式的新表. 现在,我正在使用以下功能创建星星,然后在其他功能(未显示)中使用粘贴"将它们分别添加到测试中:

in the Latex table, but produced in R already, so I can quickly produce new tables in the right format. Right now I am using the following function to create the stars, then I use 'paste' in a different function (not shown) to add them to the tests in the respective cases:

symnum(s[[p]], corr = FALSE, cutpoints = c(0,  .001,.01,.05, .1, 1), 
 symbols = c("^{***}","^{**}","^{*}","^{.}"," "))

但是也许有更好的解决方案.让我知道.

But maybe there is a better solution. Let me know.

推荐答案

尝试设置sanitize.text.function = function(x) x以关闭对非数字值的清除.

Try setting sanitize.text.function = function(x) x to turn off the sanitizing of non-numeric values.

但是,我也建议完全不使用星星.

However, I would also recommend not using stars at all.

这篇关于使用xtable生成带有重要星号(***)的Latex表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆