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

相关推荐
hhzz13 小时前
Python大数据实战(十六):音乐推荐系统——基于协同过滤算法构建个性化歌单引擎
大数据·人工智能·python·数据挖掘·数据分析
SunnyDays101114 小时前
Python PDF 转 Markdown 详解(转换整个文档,特定页面,表格,扫描 PDF)
python·pdf 转 markdown·pdf 转 md·扫描 pdf 转 md·pdf 表格转 md
2601_9547064914 小时前
云手机 API 自动化实战:Python 批量控机、挂机脚本完整实现
python·智能手机·自动化
Alan_69118 小时前
聊聊 Swagger/Postman/Apifox 的真实选型与 Python 项目实战
python·测试工具·postman
智慧物业老杨19 小时前
物业绿化数智化权责管控方案:基于工单平台的双层权限追溯模块落地实践
python
Metaphor69219 小时前
使用 Python 在 Word 文档中添加批注
python·word
FreakStudio19 小时前
WIZnet 开源方案分享:W55MH32 开发板 + 小智 AI实现以太网版本的小智机器人
python·单片机·嵌入式·大学生·面向对象·并行计算·电子diy·电子计算机
会周易的程序员19 小时前
使用 pybind11 封装 C++ 日志库 microLog 为 Python 模块
java·c++·python·物联网·架构·日志·aiot
一只专注api接口开发的技术猿20 小时前
电商评论自动化监控与情感数据分析完整落地教程(附可直接运行 Python 代码)
大数据·数据库·python·数据分析·自动化