在单文件 bookdown 文档中交叉引用 [英] Cross-referencing in a single-file bookdown document

查看:31
本文介绍了在单文件 bookdown 文档中交叉引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

bookdown 包的一项承诺是自动编号图形/表格标题和交叉引用图形/表格/部分的功能.

如果我们在 YAML 中使用 bookdown::html_document2,则声称可以为单 Rmd bookdown 启用此功能:

如何获得交叉引用以显示图形编号并成为图形的实时链接?我怎样才能按预期格式化标题?

这是我的会话信息:

<代码>>devtools::session_info()会议信息-------------------------------------------------------设定值版本 R 版本 3.3.0 (2016-05-03)系统 x86_64,mingw32用户界面 RStudio (0.99.846)语言 (EN)整理 English_Australia.1252tz 澳大利亚/悉尼日期 2016-07-02套餐 -----------------------------------------------------------包 * 版本日期源bookdown 0.0.74 2016-07-01 Github (rstudio/bookdown@8333bbb)devtools 1.12.0 2016-06-24 CRAN (R 3.3.1)摘要 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 起重机 (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)闪亮 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)

解决方案

这是 bookdown 包中的一个错误,我有 修复.如果您使用 bookdown >= 0.0.75,应该正确生成图号.

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:

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)  

解决方案

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.

这篇关于在单文件 bookdown 文档中交叉引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆