knitr一直具有智能四舍五入的优秀特性,因此您可以避免许多sprintf/round/paste0的绕路。
有一个客户抱怨我给出的小数精度不正确,我注意到忘记为可能以科学计数法打印的数字加上“$$”非常危险。但是同一位客户抱怨我的科学计数法格式很丑,因为类似latex的数学公式与主字体不匹配。
根据@yihui在已关闭问题(https://github.com/yihui/knitr/issues/864)中的评论,需要使用$$。
是否有人有智能解决方案?目前,我回到了旧日的sprintf格式化。
---
output:
html_document:
theme: cosmo
---
I use the cosmo theme because it shows the typographic problem more clearly.
```{r}
options(digits=2)
mean = c(2.31310934, 1.23456e-7)
std = c(0.31310934, 6.54321e-7)
```
digits is `r getOption("digits")`
The mean is `r mean[1]` with a standard deviation of `r std[1]`.
This looks good
The mean is `r mean[2]` with a standard deviation of `r std[2]`.
Note that the aboves looks like "1.23510".
The mean is $`r mean[2]`$ with a standard deviation of $`r std[2]`$.