【问题标题】:Knitr and bookdown : cannot number figureKnitr 和 bookdown : 不能编号数字
【发布时间】:2021-08-07 18:55:06
【问题描述】:

我正在使用 Knitr 编写报告,并尝试使用 bookdown 自动编号并参考它们。

这是我的标题:

---
title: "My title"
author: "Me"
email: "My email"
output:
  bookdown::html_document2:
    number_sections: true
    toc : true
    fig_caption : TRUE
---

```{r setup, include=FALSE}
library(bookdown)
knitr::opts_chunk$set(echo = TRUE)
setwd(dir=dirname(rstudioapi::getActiveDocumentContext()$path))
```

And my first figure :

```{r fig1,echo=F, eval=T, fig.align = 'center', fig.cap="My first figure"}
knitr::include_graphics(here::here("images", "Formule 3.png"))
```

当我编织它时,我可以看到我的身影,但在它下面,我可以看到:

(#fig:fig1)我的第一张图

我预计:

图1:我的第一个图

当我删除代码块中的 fig1 时,我得到一个自动编号,但我不知道如何引用它,因为我没有任何引用。

谁能解释我做错了什么?

提前谢谢你。

最好的问候,

让-卢克。

【问题讨论】:

  • 我无法重现您的问题,并且我得到了正确的数字编号,例如 Figure 1。您介意将sessionInfo()rmarkdown::pandoc_version() 的结果添加到您的帖子吗?

标签: html numbers knitr figure bookdown


【解决方案1】:

如果knitr::include_graphics()不起作用,您可以使用pandoc ![(#fig:tag-for-figure) Caption for the figure](/path/to/the/figure.png)支持的markdown符号进行图形插入。另请参阅r2evans' answer 了解更多详细信息(例如关于如何调整图形大小)。大家可以对照下图,如下图:

<!-- figure insertion -->

![(#fig:tag-for-figure) Caption for the figure](/path/to/the/figure.png)

<!-- Reference to the figure in a text -->

Figure \@ref(fig:tag-for-figure) shows an awesome results...

【讨论】:

  • 谢谢。其实问题出在图参考上。我加了下划线,这似乎是问题的原因。使用简单的破折号字符,它工作正常。它与 Carlos Luis Rivera 给出的示例一致。感谢他。我还有一个问题:有没有简单的方法: * 在内容列表上方添加标题 * 添加数字列表 我想在目录下面添加它,但我不知道该怎么做。预先感谢您的帮助。最好的祝福。让-卢克。
  • 如果我的回答正常,请证明by up-voting it and/or accepting it。此外,我们鼓励您创建新线程来提出与原始帖子不同的问题。当您开始在图表 TOC 上发布新帖子时,您可能会从对该主题了解更多的用户那里获得更多有用的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多