针织衫中的数字标题和标签 [英] Figures captions and labels in knitr

查看:57
本文介绍了针织衫中的数字标题和标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm new to Knitr. I'm trying to make a report using r chunks, and I can't figure out how to use captions and labels to reference the figure later on. Here's an example of what I would like to do:

---
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.

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

I would like to have a caption "Plotting example", and have a label, so I can use Figure \ref{fig.label} in the text. I have tried fig.cap and fig.lp, none of them works. I would appreciate if if someone can help.

推荐答案

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

You can achieve this by including fig_caption: yes in the header:

---
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.

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

Note that the figure caption label should be included in the caption with a double backslash, as shown above.

这篇关于针织衫中的数字标题和标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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