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

相关推荐
vvoennvv8 分钟前
【Python TensorFlow】 BiTCN-LSTM双向时间序列卷积长短期记忆神经网络时序预测算法(附代码)
python·神经网络·tensorflow·lstm·tcn
q***420518 分钟前
python的sql解析库-sqlparse
数据库·python·sql
大数据追光猿1 小时前
LangChain / LangGraph / AutoGPT / CrewAI / AutoGen 五大框架对比
经验分享·笔记·python·langchain·agent
wang_yb1 小时前
别急着转投 Polars!Pandas 3.0 带着“黑科技”杀回来了
python·databook
Jamesvalley1 小时前
flask处理所有logging
后端·python·flask
ekprada1 小时前
DAY 16 数组的常见操作和形状
人工智能·python·机器学习
柳鲲鹏1 小时前
OpenCV: 光流法python代码
人工智能·python·opencv
databook2 小时前
别急着转投 Polars!Pandas 3.0 带着“黑科技”杀回来了
后端·python·数据分析
烟袅2 小时前
为什么调用 OpenAI Tools 后,还要再请求一次大模型?——从代码看 LLM 工具调用的本质
后端·python·llm
GeekPMAlex2 小时前
Python OOP 深度解析:从核心语法到高级模式
python