简体   繁体   中英

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 . But in the newer Rmarkdown it seems they are . 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. 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)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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