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

Quarto的revealjs格式中如何本地实现图片标题居中?

解决Quarto RevealJS中图片标题居中的问题

fig-cap-location="center"参数在RevealJS格式下无法直接生效,你可以通过自定义CSS来实现图片标题的居中显示,以下是两种可行方案:

方案一:内联自定义CSS

直接在文档中添加样式块,全局控制所有图片标题的对齐方式:

---
title: "Untitled"
format: revealjs
---

<style>
.reveal .figure-caption {
  text-align: center;
  width: 100%;
}
</style>

## Centering the caption

:::{figure} https://www.r-project.org/logo/Rlogo.png
---
fig-cap: "I want this to be centered"
---
:::

方案二:使用外部CSS文件

  1. 在项目目录下创建styles.css文件,写入以下内容:
.reveal .figure-caption {
  text-align: center;
  width: 100%;
}
  1. 在Quarto文档的YAML头部引用该CSS文件:
---
title: "Untitled"
format: revealjs
css: styles.css
---

## Centering the caption

:::{figure} https://www.r-project.org/logo/Rlogo.png
---
fig-cap: "I want this to be centered"
---
:::

说明

  • 直接使用![caption](url)的普通图片语法不会生成带figure-caption类的标题元素,因此需要用Quarto的:::{figure}代码块语法来定义带标题的图片,这样自定义CSS才能作用到标题上。
  • 若需要单独控制某一张图片的标题对齐,可给该figure块添加自定义类,再针对性编写CSS规则。

内容的提问来源于stack exchange,提问作者Maël

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 14:05:01