在knitr/rmarkdown中添加beamer框架选项

use*_*808 10 latex r beamer knitr r-markdown

我正在尝试将帧编号添加到我在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}
Run Code Online (Sandbox Code Playgroud)

我用胶乳得到这个:

\begin{frame{

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

\end{frame}
Run Code Online (Sandbox Code Playgroud)

在header.tex我有这个:

\let\otp\titlepage
\renewcommand{\titlepage}{\otp\addtocounter{framenumber}{-1}}
Run Code Online (Sandbox Code Playgroud)

所以我现在的解决方法是在rmarkdown中使用普通\ maketitle,然后编译为.tex,添加[plain]选项,然后编译为pdf.但是,我想避免那个中间步骤.这是否可能在rmarkdown?

sco*_*coa 7

rmarkdown用于pandoc通过beamer/latex将Rmd文件转换为pdf.pandoc使用模板来控制转换的方式.

解决问题的一种方法是:

  1. 下载默认beamer模板 rmarkdown使用并打开它.

  2. 从这里改变第137行:

    \frame{\titlepage}
    
    Run Code Online (Sandbox Code Playgroud)

    对此:

    \frame[plain]{\titlepage} 
    
    Run Code Online (Sandbox Code Playgroud)
  3. Rmd文件中添加修改后模板的路径:

    ---
    output:
      beamer_presentation:
        includes:
          in_header: header.tex
        template:/path/to/new/template.tex
    ---
    
    Run Code Online (Sandbox Code Playgroud)

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


小智 7

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

----

# I'm the title {.plain}
Run Code Online (Sandbox Code Playgroud)

来源:Pandoc 用户指南