如何在Org模式导出HTML时自定义‘Table of Contents’目录标题?
Absolutely! You don’t need post-export JavaScript workarounds—Org mode has built-in tools to set a custom TOC title directly during export. Here are the two most practical methods:
1. Per-file or Global Variable Setup
The org-html-toc-title variable controls the text of the TOC’s H2 heading. You can set it either for a single document or across all your exports.
For a single Org file
Add this line at the top of your document (within the initial settings block) to override the title just for that file:
#+BIND: org-html-toc-title "目录" ;; Replace with your desired title text
Just make sure you have TOC enabled in your #+OPTIONS (e.g., #+OPTIONS: toc:t to display the table of contents).
For all exports globally
Add this to your Emacs configuration file (like init.el or .emacs) to set a default custom title for every Org-to-HTML export:
(setq org-html-toc-title "目录") ;; Use your preferred language's title here
2. Custom HTML Template (for advanced control)
If you want more control over the TOC’s HTML structure along with the title, create a custom HTML template:
- Create a template file (e.g.,
my-org-template.html) and modify the TOC section to use your custom title:
<div id="table-of-contents"> <h2>Your Custom TOC Title</h2> <div id="text-table-of-contents"> %TOC% </div> </div>
- Reference this template in your Org file:
#+HTML_TEMPLATE: /path/to/my-org-template.html
This method is ideal if you want to tweak styling or structure beyond just the title text.
Both approaches will generate the TOC with your desired title right on export—no post-processing required.
内容的提问来源于stack exchange,提问作者Giovanni Gigante

