图中的字幕和标签

Noo*_*osh 25 r knitr r-markdown

我是Knitr的新手.我正在尝试使用r块进行报告,我无法弄清楚如何使用标题和标签来引用该图.这是我想做的一个例子:

---
title: "Plotting"

author: "xx"

date: '2015-08-10'

output: pdf_document
---
```{r figs, echo=FALSE, fig.width=7,fig.height=6,fig.cap="plotting example"}

    par(mfrow=c(2,2))
    plot(1:10, col=2)
    plot(density(runif(100, 0.0, 1.0)))
    plot(runif(100, 0.0, 1.0),type="l")
```

in Figure \ref{fig:figs} we see examples of plotting in R.
Run Code Online (Sandbox Code Playgroud)

我想有一个标题"绘图示例",并有一个标签,所以我可以在文本中使用Figure\ref {fig.label}.我试过fig.cap和fig.lp,它们都没有用.如果有人可以提供帮助,我将不胜感激.

RHe*_*tel 49

您可以通过fig_caption: yes在标题中包含来实现此目的:

---
title: "Plotting"
output:
  pdf_document:
    fig_caption: yes
---

```{r figs, echo=FALSE, fig.width=7,fig.height=6,fig.cap="\\label{fig:figs}plotting example"}
par(mfrow=c(2,2))
plot(1:10, col=2)
plot(density(runif(100, 0.0, 1.0)))
plot(runif(100, 0.0, 1.0),type="l")
```

in Figure \ref{fig:figs} we see examples of plotting in R.
Run Code Online (Sandbox Code Playgroud)

点击这里查看截图

请注意,图标题标签应包含在标题中,并带有双反斜杠,如上所示.

  • 使用html_document时,“图1”部分不会写入html文件。 (5认同)
  • 为我工作而不说明`fig_caption:yes`。 (2认同)
  • 我想知道如何编写“图1:”部分,就像@user2955884一样 (2认同)