求助:R Markdown Beamer左图右文幻灯片编译报错(排除图片路径问题)
R Markdown制作Beamer双栏幻灯片编译报错解决
问题场景
使用R Markdown制作Beamer演示文稿,想要创建左图右文的双栏幻灯片,编写了对应代码,但编译时出现! Extra }, or forgotten \endgroup.错误,已确认图片路径正确,需排查问题。
原代码
--- title: "Herding" author: - Loana institute: - Supervised by - University date: Academic year 2017-2018 output: beamer_presentation: incremental: false theme: "Frankfurt" colortheme: "beaver" toc: true slide_level: 3 keep_tex: true classoption: aspectratio=169 header-includes: - \AtBeginSubsection{} --- \begin{frame}{Your New Slide Title} \begin{columns} \begin{column}{0.5\textwidth} % Left side: Insert your image here \includegraphics[width=\textwidth]{my_image.png} \end{column} \begin{column}{0.5\textwidth} % Right side: Insert your text here \begin{itemize} \item Point 1 \item Point 2 \item Point 3 \end{itemize} \end{column} \end{columns} \end{frame}
报错信息
! Extra }, or forgotten \endgroup. \endframe ->\egroup \begingroup \def \@currenvir {frame} l.126 \end{frame} Error: LaTeX failed to compile template.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See template.log for more info. Execution halted
解决方法
问题原因
手动添加了LaTeX原生的frame环境,但配置中已设置slide_level: 3,R Markdown会自动为对应级别的标题生成frame环境,手动嵌套frame会导致LaTeX语法冲突,出现额外的括号/分组错误。
修正后的代码
--- title: "Herding" author: - Loana institute: - Supervised by - University date: Academic year 2017-2018 output: beamer_presentation: incremental: false theme: "Frankfurt" colortheme: "beaver" toc: true slide_level: 3 keep_tex: true classoption: aspectratio=169 header-includes: - \AtBeginSubsection{} --- ### Your New Slide Title \begin{columns} \begin{column}{0.5\textwidth} % Left side: Insert your image here \includegraphics[width=\textwidth]{my_image.png} \end{column} \begin{column}{0.5\textwidth} % Right side: Insert your text here \begin{itemize} \item Point 1 \item Point 2 \item Point 3 \end{itemize} \end{column} \end{columns}
关键修改点
- 移除手动编写的
\begin{frame}{Your New Slide Title}和\end{frame} - 用R Markdown的三级标题
### Your New Slide Title定义幻灯片标题,匹配配置中的slide_level: 3,让Rmd自动生成正确的frame环境 - 保留原有的
columns双栏布局代码,图片和列表部分无需改动
内容的提问来源于stack exchange,提问作者silent_hunter
相关产品推荐
相关产品推荐

