本文介绍了Rmarkdown:将pdf文件或Word输出中的Figure X标签修改为Figure SX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Rmarkdown自动标记Figure的标题,但我希望它不是 Figure S1 ,而不是计算 Figure 1 ,即仅添加S 在那里.

我想要的输出是pdf,但如果没有,我可以用word来做.感谢您提出解决方法的建议!

解决方案

您可以在YAML部分的 header-includes:下使用一些LaTeX命令,如下所示:

  ---标题:无标题";输出:pdf_document标头包括:-\ renewcommand {\ figurename} {图S}-\ makeatletter-\ def \ fnum @ figure {\ figurename \ thefigure}-\ makeatother---```{r,fig.cap ="这是我的人物描述,fig.height = 3}情节(压力)``````{r,fig.cap =另一个图形描述",fig.height = 3}情节(iris $ Sepal.Length,iris $ Petal.Width)``` 

(R代码块中的参数 fig.height 不是必需的;我仅用它来获取同一页面中的两个图并截取屏幕截图)

I am trying to use Rmarkdown to automatically label Figure's caption, but instead of counting Figure 1, I want it to be Figure S1, i.e. just adding S there. An example here and here suggests that this is not possible using pdf output. Ok, I am fine with .doc file, but still my figure caption is not print out? I wonder what could be wrong?

Minimal example for R markdown:

    ---
title: Supporting Information
subtitle: "Iron(I) etc"
author: "Some people here"
abstract: "Added the addresses here since there is no abstract in the SI"
output:
  word_document:
    fig_caption: yes
---

```{r, include=F}
library(captioner)

figS<- captioner(prefix = "Figure S", auto_space = TRUE, levels = 1, type = NULL,  infix = ".")

figS("Figure S1", "Single-crystal X-ray structure of some text (1)", display=FALSE)

```

```{r Xray, fig.cap=figS("This is my figure description"), echo=FALSE}
plot(cars)
```

This prints correctly out Figure S1. But, now my actual figure description is missing?

My desired output is pdf, but if not, I can do with word. Thanks for suggestion how to fix this!

解决方案

You can use some LaTeX commands under header-includes: in the YAML section, as follows:

---
title: "Untitled"
output: pdf_document
header-includes:
  - \renewcommand{\figurename}{Figure S}
  - \makeatletter
  - \def\fnum@figure{\figurename\thefigure}
  - \makeatother
---

```{r, fig.cap="This is my figure description", fig.height=3}
plot(pressure)
```

```{r, fig.cap="Another figure description", fig.height=3}
plot(iris$Sepal.Length, iris$Petal.Width)
```

(The argument fig.height in the R code chunks is not necessary; I used it only to get both plots in the same page and take the screenshot)

这篇关于Rmarkdown:将pdf文件或Word输出中的Figure X标签修改为Figure SX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 03:48