Quarto输出PDF时作者元数据传递失败问题求助
解决Quarto .qmd渲染PDF时作者元数据无法正常传递的问题
直接给你两个可行的解决办法:
办法一:用模板片段+LaTeX包处理(推荐多作者场景)
这个方法能完美适配Quarto官方的作者元数据结构,同时让PDF正确显示所有信息。
- 先写好.qmd的YAML头部:
title: "测试文档" authors: - name: "张三" email: "zhangsan@example.com" affiliation: "某大学计算机学院" format: pdf: include-in-header: text: | \usepackage{authblk} template-partials: - "author-info.tex"
- 在同目录下创建
author-info.tex文件,内容如下:
$for(authors)$ \author[$authors.affiliation$]{$authors.name$ \thanks{$authors.email$}} $endfor$ \affil[$for(authors)$$authors.affiliation$$sep$, $endfor$]{}
原理是用authblk包来管理作者、邮箱和机构,通过模板片段遍历authors数组,把元数据注入LaTeX,替换默认的\author字段,避免被转成true。
如果是多作者且机构重复的情况,还可以优化模板片段:
$for(authors)$ \author[$authors.affiliation$]{$authors.name$ \thanks{$authors.email$}} $endfor$ $for(affiliations)$ \affil[$affiliations.index$]{$affiliations.name$} $endfor$
对应的YAML可以把机构单独提取:
title: "多作者测试" authors: - name: "张三" email: "zhangsan@example.com" affiliation: 1 - name: "李四" email: "lisi@example.com" affiliation: 2 affiliations: - name: "某大学计算机学院" index: 1 - name: "某大学数学系" index: 2 format: pdf: include-in-header: text: | \usepackage{authblk} template-partials: - "author-info.tex"
办法二:同时指定author和authors字段(适合简单场景)
如果需求不复杂,可以直接在YAML里同时写两个字段:authors用于Quarto的元数据管理,author直接写LaTeX格式的内容,让PDF渲染时直接读取这个值:
title: "测试文档" authors: - name: "张三" email: "zhangsan@example.com" affiliation: "某大学计算机学院" author: "张三\\thanks{zhangsan@example.com} \\affil{某大学计算机学院}" format: pdf
这样既保留了Quarto官方的元数据结构,又能让PDF正确显示作者、邮箱和机构信息。
内容的提问来源于stack exchange,提问作者Paul
相关产品推荐
相关产品推荐

