Cross-referencing in a single-file bookdown document
Asked Answered
S

1

15

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)  
Stemma answered 2/7, 2016 at 3:45 Comment(6)
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.Mistakable
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.Omni
@Omni I've updated my Q to show the output when I use output: bookdown::pdf_document2Stemma
ok, but this is an LaTex error and has nothing to do with this question. It works for me, see hereOmni
@Omni 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?Stemma
@KeithHughitt thanks for confirming. I've posted an issue here: github.com/rstudio/bookdown/issues/146Stemma
R
9

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.

Reprimand answered 7/7, 2016 at 9:38 Comment(1)
Great, yes, I've updated to the latest version and the figure numbering/cross-referencing works as expected for html. Thanks a lot!Stemma

© 2022 - 2024 — McMap. All rights reserved.