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

相关推荐
2501_915918416 小时前
uni-app 上架 iOS 应用全流程 从云打包到开心上架(Appuploader)免 Mac 上传发布指南
android·macos·ios·小程序·uni-app·iphone·webview
程序员小远6 小时前
selenium元素定位---(元素点击交互异常)解决方法
自动化测试·软件测试·python·selenium·测试工具·测试用例·交互
LEEBELOVED6 小时前
R语言基于Rselenium模拟浏览器抓取DatabaseCommons数据-连载NO.04
r语言
ColderYY6 小时前
DrissionPage自动化
python·自动化
Python大数据分析@6 小时前
如何用 Python xlwings库自动化操作 Excel?
python·自动化·excel
qq_12498707537 小时前
基于Flask的穷游网酒店数据分析系统(源码+论文+部署+安装)
后端·python·flask·毕业设计
Brianna Home7 小时前
PyTorch实战:CV模型搭建全指南
人工智能·pytorch·经验分享·python·神经网络·结对编程
喜欢吃豆7 小时前
spec-kit深度解析:AI驱动的规范驱动开发(SDD)的架构、哲学与实践启示
人工智能·驱动开发·python·架构·大模型
rengang667 小时前
28-Keras:探讨高层神经网络API及其快速原型设计能力
人工智能·python·神经网络·机器学习·keras