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

相关推荐
RSABLOCKCHAIN3 小时前
AI Agents in LangGraph-2
人工智能·python
WA内核拾荒者4 小时前
WhatsApp 账号异常检测的自动化告警系统设计
数据库·python·自动化
码流怪侠5 小时前
【GitHub】Bend:让 GPU 并行编程像写 Python 一样简单
python·github
2401_894915536 小时前
GEO 搜索优化完整源码从零部署:环境配置、集群搭建全流程
开发语言·python·tcp/ip·算法·unity
zhiSiBuYu05177 小时前
Python3 模块开发与应用实战指南
python
databook8 小时前
用方差阈值过滤掉“惰性特征”
python·机器学习·scikit-learn
Freak嵌入式8 小时前
MCU 低功耗模式解析:时钟门控、电源门控、深度休眠
人工智能·python·单片机·嵌入式硬件·开源·依赖倒置原则·micropython
weixin_BYSJ19879 小时前
springboot校园自习室管理小程序---附源码32142
java·javascript·spring boot·python·django·flask·php
2501_9159214310 小时前
iOS开发环境搭建详解 Xcode 配置与快蝎轻量级工具选择
ide·vscode·macos·ios·个人开发·xcode·敏捷流程