简体   繁体   English

带knitr的Rstudio中带有标题的表和图编号

[英]Table and Figure numbers with captions in Rstudio with knitr

In previous iterations of knitr and Rstudio, figure captions with automatic numbering were not supported . 在knitr和Rstudio的先前版本中, 不支持带有自动编号的图形标题。 But in the newer Rmarkdown it seems they are . 但是在较新的Rmarkdown中似乎是这样 Robert Flight had a nice solution which I used before, but I'm wondering if there's a tidier way to do it in the new Rmarkdown. Robert Flight有一个很好的解决方案 ,我以前使用过,但是我想知道在新的Rmarkdown中是否有一种更简洁的方法来做到这一点。 Is there? 在那儿?

Here's as far as I could get with my attempt. 这是我尽力而为的尝试。 Captions are below not above the figures and no numbers are automatically generated. 字幕在数字的下方,且不自动生成数字。

---
title: "Test for caption"
output: 
  word_document:
    fig_caption: true
---


```{r, fig.cap='oh caption my caption', echo=FALSE} 
require(ggplot2)
ggplot(iris, aes(Petal.Width, Petal.Length, color=Species)) + geom_point()
```

Session info: 会话信息:

R version 3.1.0 (2014-04-10)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252 
[2] LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] markdown_0.7.4   rmarkdown_0.2.46

loaded via a namespace (and not attached):
[1] digest_0.6.4    htmltools_0.2.4 tools_3.1.0  

看来您使用的是rmarkdown的旧版本,请尝试将其升级 (> = v0.2.65)。

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

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