15
votes

One of the promises of the bookdown package is functions for automatic numbering of figure/table captions, and cross-referencing figures/tables/sections.

This is claimed to be enabled for single-Rmd bookdown, if we use bookdown::html_document2 in the YAML: https://bookdown.org/yihui/bookdown/a-single-document.html

Looking at the raw rmarkdown for that chapter of the bookdown manual, I've tried to follow the instructions to make a single Rmd file that can use those cross-referencing functions. But I can't get it to render as expected, with cross-references.

Here's a simple example Rmd:

---
output: bookdown::html_document2
---

Here's the cross-ref: \@ref(fig:cars-fig) 

Here's the figure:

```{r cars-fig, fig.cap = 'Here is a plot about cars'}
plot(cars)
```

Here's the output I get when I click on the knit button in RStudio, the cross-references are not quite working as expected:

enter image description here

How can I get the cross-referencing to show figure numbers and be a live link to the figure? And how can I get the caption to be formatted as expected?

Here's my session info:

> devtools::session_info()
Session info -------------------------------------------------------
 setting  value                       
 version  R version 3.3.0 (2016-05-03)
 system   x86_64, mingw32             
 ui       RStudio (0.99.846)          
 language (EN)                        
 collate  English_Australia.1252      
 tz       Australia/Sydney            
 date     2016-07-02                  

Packages -----------------------------------------------------------
 package   * version date       source                           
 bookdown    0.0.74  2016-07-01 Github (rstudio/bookdown@8333bbb)
 devtools    1.12.0  2016-06-24 CRAN (R 3.3.1)                   
 digest      0.6.9   2016-01-08 CRAN (R 3.3.0)                   
 htmltools   0.3.5   2016-03-21 CRAN (R 3.2.4)                   
 httpuv      1.3.3   2015-08-04 CRAN (R 3.2.3)                   
 memoise     1.0.0   2016-01-29 CRAN (R 3.2.5)                   
 mime        0.4     2015-09-03 CRAN (R 3.2.2)                   
 miniUI      0.1.1   2016-01-15 CRAN (R 3.2.4)                   
 R6          2.1.2   2016-01-26 CRAN (R 3.2.5)                   
 Rcpp        0.12.5  2016-05-14 CRAN (R 3.3.0)                   
 rmarkdown   0.9.6   2016-05-01 CRAN (R 3.3.0)                   
 rsconnect   0.4.3   2016-05-02 CRAN (R 3.3.0)                   
 shiny       0.13.2  2016-03-28 CRAN (R 3.2.4)                   
 withr       1.0.2   2016-06-20 CRAN (R 3.3.0)                   
 xtable      1.8-2   2016-02-05 CRAN (R 3.2.5)                   
 yaml        2.1.13  2014-06-12 CRAN (R 3.2.2)  
1
I can confirm the issue. Tried a few different variations with no success. Might be worth reporting as an issue on the GH repo for bookdown.Keith Hughitt
With output: bookdown::pdf_document2 this syntax works fine. It´s the same in "normal" markdown. in PDF you can get your figures numbered, but not in HTML.J_F
@J_F I've updated my Q to show the output when I use output: bookdown::pdf_document2Ben
ok, but this is an LaTex error and has nothing to do with this question. It works for me, see hereJ_F
@J_F Right, this question is about HTML output. I've now removed the bit in the Q about PDF because that's not the main point of my question. Do you have a solution to this HTML problem?Ben

1 Answers

7
votes

This was a bug in the bookdown package and I have fixed it. The figure number should be generated correctly if you use bookdown >= 0.0.75.