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

如何在RStudio的R Markdown YAML中缩小指定文本字体大小

缩小R Markdown中YAML date字段文本字体大小的方法

因为你同时输出HTML和Word文档,两种格式的处理方式不同,分别说明:

HTML输出方案

直接在YAML的date字段里嵌入HTML标签,通过样式指定字体大小,Markdown的加粗、斜体格式依然生效:

---
title: 'XYZ*'
author: '© John Doe'
date: "<span style='font-size: 80%;'>**Citation:** *Doe J. (in press). Journal.*</span>"
output:
  html_document:
    code_folding: hide
    number_sections: yes
    theme: united
    toc: yes
    toc_depth: 3
    toc_float: yes
    fig_width: 5
    fig_height: 5
  word_document:
    toc: yes
    toc_depth: '3'
toc-title: Table of Contents
---
  • 把font-size的值改成你需要的比例(比如70%、90%)即可调整大小。

Word输出方案

Word不支持在YAML字段里直接嵌入HTML样式,得换个方式处理:

  1. 先把YAML里的date字段设为空,避免默认输出原文本
  2. 在文档开头添加R代码块,用officedown包调用Word的样式来控制字体大小:
---
title: 'XYZ*'
author: '&copy; John Doe'
date: "" # 留空避免默认输出
output:
  html_document:
    code_folding: hide
    number_sections: yes
    theme: united
    toc: yes
    toc_depth: 3
    toc_float: yes
    fig_width: 5
    fig_height: 5
  word_document:
    toc: yes
    toc_depth: '3'
toc-title: Table of Contents
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(officedown)
# 调用Word内置的"Caption"样式(默认字体较小),也可以自定义样式后替换
body_add_par("**Citation:** *Doe J. (in press). Journal.*", style = "Caption")
- 如果不想用额外包,也可以生成Word后手动调整字体,但用代码方案能实现自动化输出。

内容的提问来源于stack exchange,提问作者Simon Harmel
相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 01:42:39