You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否在同一.qmd文件中同时渲染revealjs(.html)与.pdf演示文稿?

问题

我一直在RStudio中使用Quarto制作演示文稿,偏好采用revealjs生成.html格式演示文稿,再将其转换为.pdf格式发送给学生。请问是否可以同时渲染这两种格式?

附上当前使用的Quarto配置:

---
title: "R and RStudio"
author: "RTheodoro"
institute: "USP"
format: 
   revealjs:
     logo: img/usp_logo.png
     slide-number: true
     show-slide-number: all
     preview-links: auto
     width: 1280
     height: 720
     theme: default
editor: visual
execute:
  echo: true
---

## What is R?

-   R is.....
回答

完全可以同时渲染revealjs格式的HTML和对应的PDF文件,有两种常用实现方式:

方式一:同时指定双输出格式

直接在YAML配置的format字段下同时添加revealjs和pdf(基于Beamer)的配置,Quarto会一次性生成两种格式的文件:

---
title: "R and RStudio"
author: "RTheodoro"
institute: "USP"
format: 
  revealjs:
    logo: img/usp_logo.png
    slide-number: true
    show-slide-number: all
    preview-links: auto
    width: 1280
    height: 720
    theme: default
  pdf:
    documentclass: beamer
    # 可添加PDF专属配置,比如自定义页码、主题等
editor: visual
execute:
  echo: true
---

方式二:基于RevealJS直接生成同样式PDF

如果你希望PDF完全匹配RevealJS幻灯片的视觉样式(而非Beamer格式),可以在RevealJS的配置中启用pdf选项,渲染时会自动生成对应HTML的PDF副本:

---
title: "R and RStudio"
author: "RTheodoro"
institute: "USP"
format: 
  revealjs:
    logo: img/usp_logo.png
    slide-number: true
    show-slide-number: all
    preview-links: auto
    width: 1280
    height: 720
    theme: default
    pdf: true
    # 可选:指定PDF输出文件名,避免与HTML重名
    output-file: "R-and-RStudio-slides.pdf"
editor: visual
execute:
  echo: true
---

注意事项

  • 确保环境中有必要的渲染依赖:方式二需要Quarto能调用pandoc或wkhtmltopdf,通常Quarto安装时会自带基础依赖。
  • 在RStudio中点击渲染按钮后,两种格式的文件会保存在同一目录下,可通过output-file字段分别指定文件名区分。

内容的提问来源于stack exchange,提问作者RxT

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 17:03:19