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

相关推荐
IVEN_1 天前
只会Python皮毛?深入理解这几点,轻松进阶全栈开发
python·全栈
Ray Liang1 天前
用六边形架构与整洁架构对比是伪命题?
java·python·c#·架构设计
AI攻城狮1 天前
如何给 AI Agent 做"断舍离":OpenClaw Session 自动清理实践
python
千寻girling1 天前
一份不可多得的 《 Python 》语言教程
人工智能·后端·python
AI攻城狮2 天前
用 Playwright 实现博客一键发布到稀土掘金
python·自动化运维
曲幽2 天前
FastAPI分布式系统实战:拆解分布式系统中常见问题及解决方案
redis·python·fastapi·web·httpx·lock·asyncio
孟健2 天前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
码路飞2 天前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽2 天前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers