0

我正在使用该officedown功能knit_print_block在 Rmarkdown 中打印图形标题,并带有 MS Word 输出。这是必需的,因为我正在遍历很多数字,并且需要每个都返回带标题的数字以及交叉引用。

纯文本一切都很好。我可以打印标题,也可以有一个交叉引用对象。但是,如果我尝试使用基本的 markdown 格式(在这种情况下为值上标),例如t/nmi^2^,这不会在 Word 文档中返回上标。我也尝试返回 XML 文本(作为关于knit_print_block“函数仅打印 XML 代码”的文档),但不返回上标值。下面是一个最小的 .Rmd 示例。它只是使用 mtcars 数据集制作无意义的绘图,然后尝试返回标题和书签。

---
  output: officedown::rdocx_document
---
  
```{r setup, include=FALSE}
library(officedown)
library(officer)
library(ggplot2)

```

```{r, echo = FALSE, message=FALSE, warning=FALSE, fig.width= 7, fig.height= 4, results = 'asis'}

for (i in 1:2){
  
  #make a placeholder plot
  tmp_plot = ggplot(mtcars, aes(x = mpg , y = hp )) +
      geom_point()
    
  print(tmp_plot)
  
  #build the caption
  cap_text = paste0('Density (t/nmi^2^) in sample ', i)
  
  #build the bookmark 
  fig_name = paste0('samplesummary', i)
  
  #build the caption
  tmp_fig_caption = block_caption(cap_text,
                style =  'Normal',
                autonum = run_autonum(seq_id = 'fig',
                                      pre_label = "Figure ",
                                      bkm = fig_name))
  
  #print caption
  officedown::knit_print_block(tmp_fig_caption)
  
  
}

```

Just some normal text. Are cross-refernces returned? Yep: Figure\@ref(fig:samplesummary1), Figure \@ref(fig:samplesummary2)


4

0 回答 0