如何去除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
相关产品推荐
相关产品推荐

