简体   繁体   English

使用 xtable 生成带有重要星号 (***) 的 Latex 表

[英]Use xtable to produce a Latex table with significance stars (***)

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.我目前正在使用 xtable 从 R 生成 Latex 表。它工作正常,但在其中一张表中,我对某些数字具有重要意义。 Something like this dataframe X:像这个数据框 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.我在星星之前使用 '^' 是因为在 Latex 意义中,星星在这种格式下看起来更好。 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.

If I use xtable via:如果我通过以下方式使用 xtable:

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

I get an output like the following:我得到如下输出:

 \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}

The problem here is the \\verb which was added.这里的问题是添加的 \\verb 。 If xtable didn't add it, the table would be fine for me.如果 xtable 没有添加它,该表对我来说就可以了。 So my question is: Is there a way around that?所以我的问题是:有没有办法解决这个问题? I just want significane stars which are in the format:我只想要以下格式的重要星星:

^{***} 

in the Latex table, but produced in R already, so I can quickly produce new tables in the right format.在 Latex 表中,但已经在 R 中生成,因此我可以快速生成正确格式的新表。 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.让我知道。

Try setting sanitize.text.function = function(x) x to turn off the sanitizing of non-numeric values.尝试设置sanitize.text.function = function(x) x以关闭对非数字值的sanitize.text.function = function(x) x

However, I would also recommend not using stars at all.但是,我也建议根本不要使用星星。

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

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