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

如何修改RMarkdown中目录(Table of Contents)的显示名称?

修改RMarkdown目录名称为自定义文本

方法1:通过YAML配置直接设置(推荐)

如果你的输出格式是pdf_document,无需使用LaTeX命令,直接在YAML头部指定toc-title参数即可:

---
title: "你的文档标题"
output:
  pdf_document:
    toc: true
    toc-title: "Taula de continguts"
---

这种方式由pandoc直接处理,不会和LaTeX语言包冲突,是最稳妥的方案。

方法2:针对LaTeX语言包的修改方式

如果必须用LaTeX命令调整,且你的文档使用了多语言包(比如babel),直接\renewcommand{\contentsname}会被语言包的配置覆盖,需要对应语言的captions钩子来修改:

\addto\captionscatalan{\renewcommand{\contentsname}{Taula de continguts}}

把这段代码放在RMarkdown的LaTeX代码块中,或者通过YAML的header-includes引入:

---
title: "你的文档标题"
output:
  pdf_document:
    toc: true
header-includes:
  - \addto\captionscatalan{\renewcommand{\contentsname}{Taula de continguts}}
---

这里用captionscatalan是因为你的目标文本是加泰罗尼亚语,对应babel的语言环境;如果是其他语言,替换成对应的钩子(比如captionsspanish对应西班牙语)。

为什么之前的\renewcommand{\contentsname}无效?

当LaTeX加载了babel这类多语言支持包时,文档的标题(包括目录、图表标题)会被语言包自动重置,普通的\renewcommand会被覆盖,必须使用语言包提供的\addto\captions<语言>方式来修改。

内容的提问来源于stack exchange,提问作者Maria

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 20:35:31