【发布时间】:2021-09-30 23:03:29
【问题描述】:
我正在更改我的 Rmarkdown 中图形标题的字体,并使用 bookdown 和 pandoc 来执行此操作。我的问题与:How to change the figure caption format in 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
要在 Rmarkdown 中使用 function Image,请将文件另存为“figure_caption_patch.lua”,该文件将在 YAML 元数据中的 pandoc_args 中调用。
降价
---
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)
```
输出
图 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 做到这一点。
【问题讨论】:
标签: r r-markdown pandoc bookdown