Quarto生成PDF无法正常显示中文的问题

今天在尝试使用Quarto写文档,发现当有中文时,无法正常显示:

yaml 复制代码
---
title: "中文PDF文档"
author: "作者姓名"
format: pdf
documentclass: article
---
yaml 复制代码
## 中文内容测试

这里是中文内容

## Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.

render之后效果如下,缺失了中文内容

完全没有显示中文

解决方案

方案1

  • 将文档类型修改为html

    yaml 复制代码
    ---
    title: "中文PDF文档"
    author: "作者姓名"
    format: html
    ---
  • rendor后即可正常输出,之后可以使用html转换为pdf

方案2

  • 请教了deepseek并测试了几种方法,发现可以修改yaml文件如下(我另外加入了控制边距的geometry声明)

    yaml 复制代码
    ---
    title: "中文PDF文档"
    author: "作者姓名"
    format: pdf
    documentclass: article
    header-includes:
      - \usepackage[UTF8]{ctex}
    pdf-engine: xelatex
    geometry:
      - left=2.5cm
      - right=2.5cm
      - top=2.5cm
      - bottom=2.5cm
    ---
  • 即可正常显示中文,效果如下

写在后边的tips

  • 可以在yaml文件中声明使用visual mode, 个人觉得这样更方便预览效果

    yaml 复制代码
    editor: visual
  • 在空白处键入 / 即可插入cell

相关推荐
SunnyDays10115 分钟前
如何使用 Python 将 PowerPoint(PPT 或 PPTX)转换为 Markdown
python·ppt转markdown·pptx转markdown·powerpoint转md
PiaoKe___6 分钟前
云手机原理与 Python 自动化实战:ADB、REST API、WebSocket 群控入门
python·智能手机·自动化
co_wait8 分钟前
Python 迭代器(一)
python
2501_9307077812 分钟前
使用C#代码更改或删除 PDF 中的超链接
pdf
Yolanda_20222 小时前
15.dataloader的使用
python
临床数据科学和人工智能兴趣组6 小时前
在R语言中, 使用 as.factor() 函数转换数值型变量
开发语言·r语言
杨杨杨大侠9 小时前
Jev、Kev、Laya:决策模型怎么选,什么时候需要微调?
人工智能·python·agent
LOVE️YOU9 小时前
Python 在定义函数时,究竟定义的是什么?
python
段一凡-华北理工大学9 小时前
大模型应用开发 100 天:Python + LLM 从入门到精通 day26~Prompt 调试与优化——A/B 测试与效果评估
windows·python·大模型·prompt·智能体·提示词工程·高炉智能化
Minecraft红客9 小时前
以撒的结合
python·游戏·电脑·娱乐