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

在RMarkdown Beamer中实现图片与图题并排显示

实现Beamer幻灯片中图片与图题并排显示

效果示例

想要达到的并排显示效果:
目标并排布局

用到的xkcd原图:
xkcd漫画1
xkcd漫画2

修改后的RMarkdown代码

通过LaTeX的minipage环境结合caption包可以实现图片与图题的并排布局,调整后的代码如下:

---
title: "CH6 Testing"
date: ""
fontsize: 9pt
header-includes:
 \usepackage{color}
 \usepackage{pdfpages}
 \usepackage{xeCJK}
 \usepackage{caption}  # 用于自定义图题位置
 \setbeamertemplate{itemize items}[circle] ##可以改變符號的形狀
output:
 beamer_presentation:
  latex_engine: xelatex
---

## 6.10 The local FDR

\begin{minipage}{0.45\textwidth}
  \centering
  ```{r, echo=FALSE, out.width='100%'}
  knitr::include_graphics("./frequentists_vs_bayesians.png")

\end{minipage}
\hfill # 添加左右分栏间距
\begin{minipage}{0.5\textwidth}
\captionof{figure}{While the frequentist only has the currently available data, the Bayesian can draw on her understanding of the world or on previous experience. As a Bayesian, she would know enough about physics to understand that our sun’s mass is too small to become a nova. Even if she does not know physics, she might be an empirical Bayesian and draw her prior from a myriad previous days where the sun did not go nova.}
\end{minipage}

## 关键调整说明
- 在`header-includes`中添加`\usepackage{caption}`,支持在非浮动环境中生成图题
- 用`minipage`将幻灯片分为左右两栏,可根据需求调整宽度比例
- 左侧栏放置图片,设置`out.width='100%'`让图片充满栏宽
- 右侧栏用`\captionof{figure}`添加图题,替代原代码中的`fig.cap`参数
- `\hfill`用于自动填充两栏之间的空白,保证布局整齐

内容的提问来源于stack exchange,提问作者Boyan
相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 05:55:36