【问题标题】:Change background in R Markdown beamer presentation在 R Markdown 投影仪演示文稿中更改背景
【发布时间】:2019-08-03 00:02:56
【问题描述】:

我正在 rmarkdown 中编写投影仪演示文稿,我有两种类型的框架,它们的背景应该不同。 所以我在latex中写了两个这样的函数:

\newcommand{\settitlestyle}{
\setbeamertemplate{background canvas}{%
  \includegraphics[width = \paperwidth, height = \paperheight] 
{backgroundtitle.jpg}}
} 

\setmainstyle 是完全相同的命令,但另一个 jpg。

在 YAML 中,我已经输入了一个定义函数并调用 \settitlestyle 的 tex 文件。作品。但在第一张幻灯片之后,我想切换到 mainstyle。当我在 markdownfile 中调用 \setmainstyle 时,什么也没有发生。

【问题讨论】:

    标签: r latex r-markdown beamer


    【解决方案1】:

    \setmainstyle 命令的问题在于它将在框架内使用,因此是无效的。

    为避免此问题,您可以使用与https://tex.stackexchange.com/questions/173201/beamer-template-with-different-style-options-for-frames 中相同的策略来创建将更改背景的框架选项。

    不幸的是,rmarkdown 只是忽略了用户创建的框架选项,并且只传递了一小部分预定义选项。为了欺骗 rmarkdown,可以重新使用通常不被 beamer 使用的框架选项,standout 框架选项(它只被大都会主题使用)

    ---
    output: 
      beamer_presentation:
        keep_tex: true
        includes:
          in_header: preamble.tex
    ---
    
    # frametitle 
    
    test
    
    # frametitle with different background {.standout}
    
    test
    
    # frametitle
    
    test
    

    和 preamble.tex

    \usepackage{etoolbox}
    
    \defbeamertemplate{background canvas}{mydefault}{%
      \includegraphics[width=\paperwidth,height=\paperheight]{example-image-b}
    }
    \defbeamertemplate{background canvas}{standout}{%
      \includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}
    }
    
    \BeforeBeginEnvironment{frame}{%
      \setbeamertemplate{background canvas}[mydefault]%
    }
    
    \makeatletter
    \define@key{beamerframe}{standout}[true]{%
      \setbeamertemplate{background canvas}[standout]%
    }
    \makeatother
    

    或者如果您想更改所有后续帧的背景:

    \usepackage{etoolbox}
    
    \defbeamertemplate{background canvas}{mydefault}{%
      \includegraphics[height=\paperheight,page=2]{example-image-duck}
    }
    \defbeamertemplate{background canvas}{standout}{%
      \includegraphics[height=\paperheight]{example-image-duck}
    }
    
    \setbeamertemplate{background canvas}[mydefault]%
    
    \makeatletter
    \define@key{beamerframe}{standout}[true]{%
      \setbeamertemplate{background canvas}[standout]%
    }
    \makeatother
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 2011-03-02
      • 1970-01-01
      • 2019-10-31
      • 2021-05-19
      • 2010-12-13
      相关资源
      最近更新 更多