{"action":"closed","issue":{"url":"https://api.github.com/repos/dr-harper/rmarkdown-cookbook/issues/25","repository_url":"https://api.github.com/repos/dr-harper/rmarkdown-cookbook","labels_url":"https://api.github.com/repos/dr-harper/rmarkdown-cookbook/issues/25/labels{/name}","comments_url":"https://api.github.com/repos/dr-harper/rmarkdown-cookbook/issues/25/comments","events_url":"https://api.github.com/repos/dr-harper/rmarkdown-cookbook/issues/25/events","html_url":"https://github.com/dr-harper/rmarkdown-cookbook/issues/25","id":351889117,"node_id":"MDU6SXNzdWUzNTE4ODkxMTc=","number":25,"title":"How to add numbered figure caption in a document ? ","user":{"login":"cderv","id":6791940,"node_id":"MDQ6VXNlcjY3OTE5NDA=","avatar_url":"https://avatars1.githubusercontent.com/u/6791940?v=4","gravatar_id":"","url":"https://api.github.com/users/cderv","html_url":"https://github.com/cderv","followers_url":"https://api.github.com/users/cderv/followers","following_url":"https://api.github.com/users/cderv/following{/other_user}","gists_url":"https://api.github.com/users/cderv/gists{/gist_id}","starred_url":"https://api.github.com/users/cderv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cderv/subscriptions","organizations_url":"https://api.github.com/users/cderv/orgs","repos_url":"https://api.github.com/users/cderv/repos","events_url":"https://api.github.com/users/cderv/events{/privacy}","received_events_url":"https://api.github.com/users/cderv/received_events","type":"User","site_admin":false},"labels":[{"id":914826361,"node_id":"MDU6TGFiZWw5MTQ4MjYzNjE=","url":"https://api.github.com/repos/dr-harper/rmarkdown-cookbook/labels/more%20information","name":"more information","color":"a2eeef","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-08-19T09:41:04Z","updated_at":"2018-10-14T12:28:44Z","closed_at":"2018-10-14T12:28:43Z","author_association":"CONTRIBUTOR","body":"This is an old question than know have an answer with bookdown, but can also be dealt without it. Should both be mentionned ? \r\n\r\n## with bookdown \r\n**Easiest solution**\r\nAutomatic numbering and cross referencing\r\nhttps://bookdown.org/yihui/bookdown/a-single-document.html\r\n\r\n## without bookdown\r\nIt is possible to number figure and add caption without bookdown.\r\n* Use a custom function and `fig.cap` chunk option\r\n````r\r\n# Incremental Figure Numbers\r\n\r\n```{r setup, include=FALSE}\r\nfn = local({\r\n  i = 0\r\n  function(x) {\r\n    i <<- i + 1\r\n    paste('Figure ', i, ': ', x, sep = '')\r\n  }\r\n})\r\n```\r\n\r\n```{r test-a, fig.cap=fn('this is one plot')}\r\nplot(1:10)\r\n```\r\n\r\n```{r test-b, fig.cap=fn('another plot')}\r\nplot(rnorm(10))\r\n```\r\n````\r\nSource : [knitr example](https://github.com/yihui/knitr-examples/blob/master/070-caption-num.Rmd)\r\n\r\n* Use [`captioner`](https://github.com/adletaw/captioner) 📦 \r\n\r\n## Related SO question\r\n* https://stackoverflow.com/questions/13848137/figure-captions-references-using-knitr-and-markdown-to-html"}}
{"actor":{"display_login":"dr-harper"}}