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

如何在R Markdown的Beamer演示中仅修改封面背景颜色?

仅修改Beamer封面背景色的解决方案

直接使用\setbeamercolor{background canvas}{bg=red}会全局修改所有幻灯片的背景色,这是因为该命令会设置全局样式。要仅为封面设置背景色,需利用Beamer的钩子命令控制样式生效范围:

修改后的YAML配置

---
title: "Titulo"
subtitle: "Subtitulo"
author: "Nombre"
date: "2023-07-10"
output:
  beamer_presentation:
    incremental: true
    theme: "Rochester"
    colortheme: "default"
    fonttheme: "structurebold"
    toc: false
    slide_level: 3
    keep_tex: true
header-includes:
  - \usepackage{ragged2e}
  - \usepackage{color}
  - \usepackage{listings}
  - \AtBeginSubsection{}
  - \titlegraphic{\includegraphics[width = 3cm]{logo}}
  - \AtBeginDocument{
      \setbeamercolor{background canvas}{bg=red}
      \AtNextSlide{\restorebeamercolor{background canvas}}
    }
---

代码说明

  • \AtBeginDocument{...}:在文档初始化阶段执行内部代码
  • \setbeamercolor{background canvas}{bg=red}:将当前幻灯片(即封面)的背景色设置为红色
  • \AtNextSlide{\restorebeamercolor{background canvas}}:指定从下一张幻灯片开始,恢复background canvas的默认颜色设置

内容的提问来源于stack exchange,提问作者Roger Milian Gonzales

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 06:01:11