在knitr/rmarkdown中添加beamer帧选项

17

我正在尝试在使用rmarkdown编写的Beamer演示文稿中添加帧编号。 但是,我想使用\begin{frame}[plain]选项(来自此处的第二个答案:https://tex.stackexchange.com/questions/82794/removing-page-number-from-title-frame-without-changing-the-theme),隐藏标题页上的编号。但是,当从rmarkdown编译到tex时,\titlepage已经创建了一个框架环境,因此实际上我得到了双框架,从而出现错误。

因此,当编译以下代码时:

---
output:
  beamer_presentation:
    includes:
      in_header: header.tex
---

\begin{frame}[plain]
\titlepage
\end{frame}

我在LaTeX中得到了这个:

\begin{frame{

  \begin{frame}
     \titlepage
  \end{frame}

\end{frame}
在header.tex文件中,我有以下代码:
\let\otp\titlepage
\renewcommand{\titlepage}{\otp\addtocounter{framenumber}{-1}}

那么我现在的解决方法是在rmarkdown中使用一个简单的\maketitle,然后编译为.tex,添加[plain]选项,再编译为pdf。然而,我想避免这个中间步骤。这在rmarkdown中可能吗?

2个回答

10

rmarkdown使用pandoc通过beamer/latex将Rmd文件转换为pdf。 pandoc使用模板来控制转换过程。

解决问题的一种方法是:

  1. Download the default beamer template rmarkdown uses and open it.

  2. Change line 137 from this :

    \frame{\titlepage}
    

    To this :

    \frame[plain]{\titlepage} 
    
  3. Add the path to your modified template in your Rmd file :

    ---
    output:
      beamer_presentation:
        includes:
          in_header: header.tex
        template:/path/to/new/template.tex
    ---
    

请注意,您需要指定完整路径,或将模板存储在 pandoc 可以找到的位置(Linux机器上的 ~/.pandoc/templates)。


9
在标题后面添加{.plain},如下所示:
----

# I'm the title {.plain}

Source: Pandoc User’s Guide


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接