如何调整LaTex投影仪主题以将其应用到rmarkdown :: beamer_presentation中 [英] How to adapt a LaTex beamer theme to apply it in an rmarkdown::beamer_presentation

查看:126
本文介绍了如何调整LaTex投影仪主题以将其应用到rmarkdown :: beamer_presentation中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 rmarkdown :: beamer_presentation 中应用 LaTex投影仪主题.自定义主题包含 beamerthemeTHEMENAME.sty beamercolorthemeTHEMENAME.sty beamerfontthemeTHEMENAME.sty beamerinnerthemeTHEMENAME.sty beamerouterthemeTHEMENAME.sty .如果模板是从我的YAML标头中获取的,则该针织演示文稿看起来与通过应用自定义主题直接从LaTex生成的投影仪演示文稿不太接近.

I would like to apply a LaTex beamer theme in an rmarkdown::beamer_presentation. The custom themes contains a beamerthemeTHEMENAME.sty, beamercolorthemeTHEMENAME.sty, beamerfontthemeTHEMENAME.sty, beamerinnerthemeTHEMENAME.sty, beamerouterthemeTHEMENAME.sty. If the template is sourced within my YAML header, the knitted presentation does not look very close to a beamer presentation generated straight from LaTex by applying the custom theme.

因此,修改或增强演示文稿的的哪些内容需要修改,或者需要从 beamer主题中移出,例如到 template.tex includes *?

Thus, which contents of the beamertheme*.sty to modify or enhance the presentation require modification or need to be moved from the beamer theme, e.g. to template.tex and includes*?

尤其是,我正在努力使用在 beamerouterthemeTHEMENAME.sty 中定义的以下框架模板: \ titleframe \ tocframe \ closingframe

In particular, I am struggling on using the following frame templates defined in beamerouterthemeTHEMENAME.sty: \titleframe, \tocframe, \closingframe

对于在 beamerouterthemeTHEMENAME.sty 中定义的边界,拥有从徽标到目录幻灯片的超链接非常好(例如页码是链接到附录).下面提供了MWE.任何帮助将不胜感激.

For the footline defined in beamerouterthemeTHEMENAME.sty, it would be very nice to have a hyperlink from the logo to the table of contents slide (like the page numbers are linked to the appendix). An MWE is provided below. Any help is greatly appreciated.

---
title: "MWE"
subtitle: "Beamer presnetation with R-markdown"
institute: "some place"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
  # beamer_presentation: default
  bookdown::pdf_book:
    base_format: rmarkdown::beamer_presentation
    # includes:
    #  - in_header: preamble.tex
    theme: "THEMENAME"
    latex_engine: xelatex
    toc: false
    slide_level: 2
---


​```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
​```

# Random presentation

## TOC - Table of Contents {.unnumbered}

\tableofcontents
\label{contents}

## Slide with Bullets

- Bullet 1
- Bullet 2
- Bullet 3

## Apendix
\appendix

beamerthemeTHEMENAME.sty

\usepackage[utf8]{inputenc}

% Tizk, textpos, graphics
\RequirePackage{tikz}
\RequirePackage{textpos}
\RequirePackage{xcolor}
\RequirePackage{booktabs}

% Beamer settings
\usecolortheme{THEMENAME}
\useoutertheme{THEMENAME}
\setbeamertemplate{navigation symbols}{}

\mode<all>

beamercolorthemeTHEMENAME.sty

\mode<presentation>
\definecolor{THEMECOL}{RGB}{162,48,47}  % red
\definecolor{THEMEgray}{RGB}{110,110,101}% gray

\colorlet{titlefgcolor}{THEMECOL} % color of box
\colorlet{titlebgcolor}{THEMEgray} % color of box

\setbeamercolor*{title}{fg=THEMECOL}    % presentation title 
\setbeamercolor*{author}{fg=THEMECOL}   % author
\setbeamercolor*{date}{fg=THEMECOL} % date
\mode<all>

beamerouterthemeTHEMENAME.sty

\mode<presentation>

% Redefine \insertshortinstitute to allow multiple lines
\makeatletter
\renewcommand{\insertshortinstitute}{\beamer@shortinstitute}
\makeatother

% Title frame
\def\titlefigure{img/my_bg}
\newlength\titleboxwidth
\setlength{\titleboxwidth}{0.33\textwidth}
\newcommand{\titleframe}{%
    {
        \setbeamertemplate{background}{
            \begin{tikzpicture}
            \useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
            \ifx\titlefigure\empty
                \fill[titlebgcolor] (6.3mm,6.4mm) rectangle (\the\paperwidth-8.3mm,\the\paperheight-13mm);
            \else
                \node at (current page.center) [anchor=center,yshift=-3.5mm] {\includegraphics[width=\the\paperwidth-19mm]{\titlefigure}};
            \fi
            \node at (current page.north east) [anchor=base east, xshift=-8.3mm, yshift=-6.3mm, align=left, inner sep=0mm, font=\fontsize{5.5}{6.6}\selectfont] {
                \insertshortinstitute
            }; 
            \node at (current page.north west) [anchor=south west, inner sep=0mm, xshift=8.3mm, yshift=-8.6mm] {
                \includegraphics[height=3.8mm]{img/my_logo}
            }; 
            \end{tikzpicture}
        }
        \setbeamertemplate{footline}{}
        \begin{frame}[noframenumbering]
            \begin{tikzpicture}
                \useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
                \node [
                    shift={(-11.5mm,-1.8mm)},
                    fill=titlefgcolor,
                    minimum width=0.46\paperwidth,
                    minimum height=18mm,
                    anchor=west,
                    inner sep=4mm
                    ] at (current page.west) {
                        \hspace*{9mm}
                        \begin{minipage}{\titleboxwidth}
                            \raggedright
                            \usebeamerfont{title}\usebeamercolor[fg]{title}\inserttitle\\[3mm]
                            \usebeamerfont{author}\usebeamercolor[fg]{author}\insertauthor\\
                            \usebeamerfont{date}\usebeamercolor[fg]{date}\insertdate
                        \end{minipage}          
                    };
            \end{tikzpicture}
        \end{frame}
    }
}

% TOC frame
\newcommand{\tocframe}{%
    \begin{frame}
      \frametitle{Outline}
      \tableofcontents
    \end{frame}
}

% Section title frame
\AtBeginSection[]
{
    \begin{frame}
      \frametitle{Outline}
      \large
      \tableofcontents[currentsection] 
    \end{frame}
}

\newenvironment{closingframe}{
    \setbeamertemplate{background}{
        \begin{tikzpicture}
        \useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
        \node at (current page.north west) [anchor=base west, xshift=8mm, yshift=-10mm, align=left] {
            \includegraphics[width=23mm]{img/my_logo.png}
        }; 
        \end{tikzpicture}
    }
    \setbeamertemplate{footline}{}
    \addtolength{\headsep}{10mm}
    \begin{frame}[noframenumbering]
}%
{
    \end{frame}
}%

% Footline
\setbeamertemplate{footline}{
    \leavevmode%
    \hyperlink{contents}{\includegraphics[width=12mm,trim=0mm 0.4mm 0mm 0mm]{img/my_logo.png}}
    \hfill
    \hyperlinkappendixstart{\insertframenumber/\inserttotalframenumber}
    \vspace{3mm}
}

\mode<all>

推荐答案

您可以对降价文档进行以下肮脏的入侵:

You can make the following dirty hacks to the markdown document:

  • 使用 \ AtBeginDocument {\ title {MWE} \ titleframe} 代替yaml标题,以消除烦人的自动标题降价插入(甚至不使用 \ maketitle,因此无法进行任何合理的修改)并添加自定义标题命令

  • Instead of the yaml title, use \AtBeginDocument{\title{MWE}\titleframe} to suppress the annoying automatic title markdown inserts (which does not even uses \maketitle, so one can't make any reasonable modifications) and add your custom title command

\ AtEndDocument {\ begin {closingframe} lalala \ end {closingframe}} 添加结束框[用您喜欢的文本替换lalala]

\AtEndDocument{\begin{closingframe}lalala\end{closingframe}} to add your closing frame [replace lalala with whatever text you like]

添加 \ makeatletter \ beamer @ ignorenonframefalse \ makeatother 来烦人地自动禁止使用markdown选项,并且不允许框架使用任何包装器

add \makeatletter\beamer@ignorenonframefalse\makeatother to suppress options markdown annoyingly automatically uses and which don't allow any wrappers for frames

您可以使用

``` {=latex}
\end{frame}
\tocframe
\begin{frame}
```

使用您的 \ tocframe 宏,但是我对此并没有多大用处,因为markdown会在所有合理的位置自动插入这样的帧(然后在所有不合理的位置插入更多的帧)同样,只是因为它似乎很烦人...)

to use your \tocframe macro, however I don't see much use for this, as markdown will automatically insert such frames at all reasonable places (and then a couple of more at all unreasonable places as well, just because it seems to enjoy being annoying...)

---
subtitle: "Beamer presnetation with R-markdown"
institute: "some place"
date: "`r format(Sys.time(), '%B %d, %Y')`"
author: "Donald Duck"
output:
  # beamer_presentation: default
  bookdown::pdf_book:
    base_format: rmarkdown::beamer_presentation
    # includes:
    #   in_header: preamble.tex
    theme: "THEMENAME"
    latex_engine: xelatex
    toc: false
    slide_level: 2
    keep_tex: true 
header-includes:
  - \AtBeginDocument{\title{MWE}\titleframe}    
  - \AtEndDocument{\begin{closingframe}lalala\end{closingframe}}
  - \makeatletter\beamer@ignorenonframefalse\makeatother
---

# Random presentation

## TOC - Table of Contents {.unnumbered}

\tableofcontents
\label{contents}

``` {=latex}
\end{frame}
\tocframe
\begin{frame}
```

## Slide with Bullets

- Bullet 1
- Bullet 2
- Bullet 3

``` {=latex}
\end{frame}
\appendix
\begin{frame}
```
## Apendix

现在是主题:

  • 如果自恐龙灭绝以来某个时刻的tex分布已更新,那么您就不需要 \ usepackage [utf8] {inputenc} .这是当前乳胶发行版中的默认设置.另外,rmarkdown会自动将其插入.

  • if your tex distribution has been updated at one point since the dinosaurs gone extinction, then you don't need \usepackage[utf8]{inputenc}. That's the default in current latex distributions. Also rmarkdown will automatically insert this.

您不需要 \ RequirePackage {xcolor} .投影机不仅已经自动加载了此文件,而且rmarkdown会自动将其添加到文档中,并将其包含在这个烦人的冗长的不合适软件包列表中.

you don't need \RequirePackage{xcolor}. Not only does beamer already load this automatically, but it will also be included in this annoyingly long list of unsuitable packages rmarkdown automatically adds to the document.

\ titleframe 宏也需要进行一些修改,因为主题确实滥用了 \\ 来换行,并且不测试标题,作者和日期宏实际上已被填充.结合起来,这将严重失败...

The \titleframe macro also needs a couple of modifications because the theme does abuse \\ for line breaks and does not test if title, author and date macros are actually filled. Combined this will fail spectacularly...

您可能还想为背景和标题框的字体使用不同的颜色....我在背景中混合了一些白色以使字体可见

you might also want to use different colours for the background and the font of the title box.... I mixed a bit of white to the background to make the font visible

\newcommand{\titleframe}{%
    {
        \setbeamertemplate{background}{
            \begin{tikzpicture}
            \useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
            \ifx\titlefigure\empty
                \fill[titlebgcolor] (6.3mm,6.4mm) rectangle (\the\paperwidth-8.3mm,\the\paperheight-13mm);
            \else
                \node at (current page.center) [anchor=center,yshift=-3.5mm] {\includegraphics[width=\the\paperwidth-19mm]{\titlefigure}};
            \fi
            \node at (current page.north east) [anchor=base east, xshift=-8.3mm, yshift=-6.3mm, align=left, inner sep=0mm, font=\fontsize{5.5}{6.6}\selectfont] {
                \insertshortinstitute
            }; 
            \node at (current page.north west) [anchor=south west, inner sep=0mm, xshift=8.3mm, yshift=-8.6mm] {
                \includegraphics[height=3.8mm]{example-image}
            }; 
            \end{tikzpicture}
        }
        \setbeamertemplate{footline}{}
        \begin{frame}[noframenumbering]
            \begin{tikzpicture}
                \useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
                \node [
                    shift={(-11.5mm,-1.8mm)},
                    fill=titlefgcolor!50!white,
                    minimum width=0.46\paperwidth,
                    minimum height=18mm,
                    anchor=west,
                    inner sep=4mm
                    ] at (current page.west) {
                        \hspace*{9mm}
                        \begin{minipage}{\titleboxwidth}
                            \raggedright
                            \usebeamerfont{title}\usebeamercolor[fg]{title}\inserttitle\par
                            \usebeamerfont{author}\usebeamercolor[fg]{author}\insertauthor\par
                            \usebeamerfont{date}\usebeamercolor[fg]{date}\insertdate
                        \end{minipage}          
                    };
            \end{tikzpicture}
        \end{frame}
    }
}

对于脚注,请使用由目录"部分创建的超链接目标

For the footline, use the hyperlink target that is created by your toc section

% Footline
\setbeamertemplate{footline}{
    \leavevmode%
    \hyperlink{toc---table-of-contents}{\includegraphics[width=12mm,trim=0mm 0.4mm 0mm 0mm]{example-image}}
    \hfill
    \hyperlinkappendixstart{\insertframenumber/\inserttotalframenumber}
    \vspace{3mm}
}

[[我猜我在这个答案中使用 annoying 的次数表明,使用rmarkdown进行的工作在普通的投影仪文档中要花2秒的时间要困难得多]

[I guess the number of times I used annoying in this answer shows how much more difficult rmarkdown makes a job that would have taken 2 seconds in a normal beamer document]

这篇关于如何调整LaTex投影仪主题以将其应用到rmarkdown :: beamer_presentation中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆