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

如何让R Markdown Beamer幻灯片正文顶对齐但章节标题居中?

解决R Markdown Beamer正文顶对齐但章节标题页居中的问题

要实现正文幻灯片全局顶对齐,同时单独的章节标题页保持居中,可以通过添加LaTeX代码重新定义章节标题页的格式,覆盖classoption: t带来的全局顶对齐效果。

具体步骤

在YAML头部之后,插入以下LaTeX代码,重新设置章节标题页的垂直对齐方式:

\makeatletter
\renewcommand{\beamer@sectionpage}[1][t]{
  \begingroup
    \centering
    \begin{beamercolorbox}[sep=12pt,center]{part title}
      \usebeamerfont{section title}\insertsection\par
    \end{beamercolorbox}
  \endgroup
}
\makeatother

完整示例代码

---
title: "Your Presentation Title"
author: "Your Name"
date: "`r Sys.Date()`"
output:
  beamer_presentation:
classoption: t
---

\makeatletter
\renewcommand{\beamer@sectionpage}[1][t]{
  \begingroup
    \centering
    \begin{beamercolorbox}[sep=12pt,center]{part title}
      \usebeamerfont{section title}\insertsection\par
    \end{beamercolorbox}
  \endgroup
}
\makeatother

# Section 1

## Slide 1

Content here.

# Section 2

## Slide 2

More content here.

原理说明

  • classoption: t 会让所有幻灯片默认顶对齐,包括自动生成的章节标题页。
  • 上述LaTeX代码重新定义了\beamer@sectionpage命令,强制章节标题页内容居中显示,同时不影响其他正文幻灯片的顶对齐设置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 23:42:08