我正在更改 R Markdown 中图形标题的字体并使用bookdown
和 pandoc 这样做。我的问题与以下问题密切相关:如何更改bookdown中的图形标题格式?。我能够获得正确的图形编号,并且能够更改标题的“图 1”部分的格式。但是,我无法弄清楚如何删除输出中的冒号(即“图 1:.”)。
最小的例子
Pandoc 函数(取自here)
function Image (img)
img.caption[1] = pandoc.Strong(img.caption[1])
img.caption[3] = pandoc.Strong(img.caption[3])
img.caption[4] = pandoc.Strong(". ")
return img
end
To use function Image
在R Markdown中,将文件保存为“figure_caption_patch.lua”,该文件将在pandoc_args
在 YAML 元数据中。
R Markdown
---
title: Hello World
author: "Somebody"
output:
bookdown::word_document2:
fig_caption: yes
number_sections: FALSE
pandoc_args: ["--lua-filter", "figure_caption_patch.lua"]
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Test
Some text (Figure \@ref(fig:Xray)). Some text followed by a figure:
```{r Xray, fig.cap="Single-crystal X-ray structure of some text", echo=FALSE}
plot(cars)
```
Output
图1:。这是一个标题。
所需输出
图1。这是一个标题。
在 pandoc 函数中,我尝试对字符串进行子集化img.caption[3]
,但没有成功。我尝试了以下方法:
img.caption[3] = pandoc.Strong(string.sub(img.caption[3], 1, 1))
我知道如果我使用 R,那么我可以这样做:
a = c("words", "again")
substring(a, 1, 1)[1]
#output
[1] "w"
但不确定如何使用 pandoc 执行此操作。