
quarto-authoring
热门当用户明确使用 Quarto、.qmd 文件、_quarto.yml、Quarto 项目,或使用 callout 提示块、交叉引用、文献引用、Mermaid 图表、扩展、网站、图书、演示文稿和报告等 Quarto 特性时使用此技能。当用户明确提出将现有项目从 R Markdown、bookdown、blogdown、xaringan、distill 或 Jupyter notebook 迁移/对比到 Quarto 时也可使用。除非明确提及 Quarto 或迁移到 Quarto,否则不要用于一般的 R Markdown 或相关格式问题。
当用户明确使用 Quarto、.qmd 文件、_quarto.yml、Quarto 项目,或使用 callout 提示块、交叉引用、文献引用、Mermaid 图表、扩展、网站、图书、演示文稿和报告等 Quarto 特性时使用此技能。当用户明确提出将现有项目从 R Markdown、bookdown、blogdown、xaringan、distill 或 Jupyter notebook 迁移/对比到 Quarto 时也可使用。除非明确提及 Quarto 或迁移到 Quarto,否则不要用于一般的 R Markdown 或相关格式问题。
Quarto Authoring(Quarto 文档编写)
本技能基于 Quarto CLI v1.9.36 (2026-03-24)。
场景与参考指南
任务:编写新的 Quarto 文档
参考:先遵循下方的“QMD 核心要点”,再查阅具体的参考文件
任务:添加交叉引用
参考:references/cross-references.md
任务:配置代码块
参考:references/code-cells.md
任务:添加带有题注(Caption)的图片
参考:references/figures.md
任务:创建表格
参考:references/tables.md
任务:添加文献引用与参考文献目录
参考:references/citations.md
任务:添加 callout 提示块
参考:references/callouts.md
任务:添加图表(Mermaid、Graphviz)
参考:references/diagrams.md
任务:控制页面布局
参考:references/layout.md
任务:使用 Shortcode 简短代码
参考:references/shortcodes.md
任务:添加条件内容
参考:references/conditional-content.md
任务:使用 Div 和 Span
参考:references/divs-and-spans.md
任务:配置 YAML Front Matter
参考:references/yaml-front-matter.md
任务:查找与使用扩展
参考:references/extensions.md
任务:应用 Markdown 代码检查规则(Linting)
参考:references/markdown-linting.md
任务:选择或配置计算引擎(knitr、jupyter、julia)
参考:references/engines.md
项目迁移(仅适用于转换现有项目)
编写新的 Quarto 文档时请勿阅读这些参考文件。
仅当用户明确要求转换或迁移现有项目时,才阅读与源格式对应的参考:
- 从 R Markdown (.Rmd) 迁移到 Quarto:references/conversion-rmarkdown.md
- bookdown 项目:references/conversion-bookdown.md
- xaringan 幻灯片:references/conversion-xaringan.md
- distill 文章:references/conversion-distill.md
- blogdown 网站:references/conversion-blogdown.md
- Jupyter notebook (.ipynb) 与 Quarto 相互转换:references/conversion-jupyter.md
QMD 核心要点
基础文档结构
---
title: "文档标题"
author: "作者姓名"
date: today
format: html
---
正文内容写在这里。
一个 Quarto 文档主要由两部分组成:
- YAML Front Matter:位于顶部、使用
---包裹的元数据与配置。 - Markdown 内容:使用标准 Markdown 语法的正文部分。
Div 与 Span
Div 使用三个冒号的围栏语法:
::: {.class-name}
Div 内部的内容。
:::
Span 使用方括号语法:
这是 [重要文本]{.highlight}。
详细信息:references/divs-and-spans.md
代码块选项语法
代码块以三个反引号加上大括号内的语言标识符开头。
代码块是可以被执行并生成输出的代码区域。
Quarto 使用语言对应的注释符号 + | 来指定单元格选项。选项使用连字符而非点(例如:使用 fig-cap 而非 fig.cap)。
- R、Python、Julia:
#| - Mermaid:
%%| - Graphviz/DOT:
//|
```{language}
#| label: fig-example
#| echo: false
#| fig-cap: "散点图示例。"
## 生成图表的代码
```
在 YAML front matter 中设置文档级的默认值:
execute:
echo: false
warning: false
缓存 — 关键引擎差异: 仅针对 R 代码块(knitr 引擎)建议使用 #| cache: true。
切勿为其他语言的代码块建议该选项 — 它无法生效且会被静默忽略。
在使用 knitr 以外的引擎时,唯一正确的方法是在顶层 YAML front matter 中配置 execute: cache: true。
Python/Jupyter 需要安装 jupyter-cache(pip install jupyter-cache):
execute:
cache: true
交叉引用
标签必须以类型前缀开头。使用 @ 进行引用:
- 图片:
fig-前缀,例如:#| label: fig-plot→@fig-plot - 表格:
tbl-前缀,例如:#| label: tbl-data→@tbl-data - 章节:
sec-前缀,例如:{#sec-intro}→@sec-intro - 公式:
eq-前缀,例如:{#eq-model}→@eq-model
```{language}
#| label: fig-plot
#| fig-cap: "图表标题。"
## 生成图表的代码
```
结果请参见 @fig-plot。
详细信息:references/cross-references.md
Callout 提示块
共五种类型:note、warning、important、tip、caution。
::: {.callout-note}
这是一个 note 提示块。
:::
::: {.callout-warning}
## 自定义标题
这是一个带有自定义标题的 warning 警告块。
:::
图片
{#fig-name fig-alt="替换文本"}
子图组(Subfigures):
::: {#fig-group layout-ncol=2}
{#fig-sub1}
{#fig-sub2}
该组合图的主标题。
:::
表格
::: {#tbl-example}
| 列 1 | 列 2 |
| ---- | ---- |
| 数据 1 | 数据 2 |
表格标题。
:::
详细信息:references/tables.md
文献引用
根据 @smith2020 的研究,结果显示……
多条文献引用 [@smith2020; @jones2021]。
在 YAML 中配置:
bibliography: references.bib
csl: apa.csl
常见工作流
创建 HTML 文档
title: "我的报告"
author: "您的名字"
date: today
format:
html:
toc: true
code-fold: true
theme: cosmo
创建 PDF 文档
title: "我的报告"
format:
pdf:
documentclass: article
papersize: a4
创建 RevealJS 演示文稿
---
title: "我的演示文稿"
format: revealjs
---
## 第一张幻灯片
这里是内容。
## 第二张幻灯片
更多内容。
配置 Quarto 项目
在项目根目录下创建 _quarto.yml:
project:
type: website
website:
title: "我的网站"
navbar:
left:
- href: index.qmd
text: 首页
- href: about.qmd
text: 关于
format:
html:
theme: cosmo





