You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何去除RMarkdown中自定义图题与自动编号间的空格?

解决RMarkdown图题「S」与编号间空格的问题

方法1:自定义图题标签格式

修改YAML头部的header-includes配置,通过caption包的\\DeclareCaptionLabelFormat自定义无空格的标签格式,替代直接设置name参数:

---
title: "Test"
author: "Shawn Hemelstrand"
date: "`r Sys.Date()`"
output: 
  pdf_document
header-includes:
- \\usepackage{caption}
- \\DeclareCaptionLabelFormat{supplement}{#1 S#2}
- \\captionsetup[figure]{labelformat=supplement}
---

配置后,图题会自动生成为「Figure S1」「Figure S2」的格式,「S」与编号之间无多余空格。

方法2:重定义编号格式并移除分隔空格

另一种思路是重定义图的编号规则,同时去掉名称与编号间的默认分隔空格:

---
title: "Test"
author: "Shawn Hemelstrand"
date: "`r Sys.Date()`"
output: 
  pdf_document
header-includes:
- \\usepackage{caption}
- \\captionsetup[figure]{name=Figure, labelsep=none}
- \\renewcommand{\\thefigure}{S\\arabic{figure}}
---

该方法直接让图编号变为「S1」「S2」,再移除「Figure」与编号间的空格,最终得到目标格式。

测试用绘图代码保持不变:

```{r plot,echo=FALSE, fig.cap="Some informative description."}
plot(iris$Petal.Width,
     iris$Petal.Length)
内容的提问来源于stack exchange,提问作者Shawn Hemelstrand
相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 08:28:22