• Home
  • About
    • Chi's blog photo

      Chi's blog

      Share and save some study notes about health economics and policy.

    • Learn More
    • Github
    • StackOverflow
  • Posts
    • All Posts
    • All Tags
  • Projects

[#10] - A easy way to make academic slides in Beamer

21 Jul 2020

Reading time ~1 minute

Shen, Chi

July 21 2020, New Haven, CT

转眼间,纽村的天已经热起来了,在后院时常还能见到许多年未曾见过的萤火虫,不得不说美国的自然环境还是没得挑的,但是超级大国的新冠疫情依然没有好转的迹象。

这个月最令人愉悦的是总算把论文的初稿完成了,算是了了一大块心病,难得可以把节奏放慢一些,感受一下美国农村的生活。

前段时间在公众号里写了一个用reveal.js做ppt的方法介绍,确实方便了不少,而去不用花很多时间去关注格式问题就可以做出很美观的样式,但是最近准备着手做论文答辩的ppt,却发现一个问题,如果用reveal.js做学术性报告的ppt,要花比较多的时间在做template的设定上,感觉还是不太方便。

后来意外试了下Beamer,感觉还不错,虽然theme比较单调(丑陋),但是学术报告么,土就土点吧,方便就行。不过Beamer有个不好的地方,因为是通过LaTeX语法编译的,所以LaTeX有的问题它都有,比如对中文的支持需要折腾一下,比如要安装MixTeX等一类的套件。

不过RStudio已经有了比较不错的解决方案,比如TinyTex,已经用起来很方便了,不过我不太习惯在RStudio中写纯文本,而去目前也很少在ppt中用到inline code chunk输出的结果,所以依然还是用的VS Code的Markdown Preview Enhanced 插件。下面是一个例子:

1 设置yaml

yaml就是配置pandoc转换时的参数,如果不想在每个md文档中都写上这么一段,也可以单独存储为_output.yaml,放在md文件相同的目录下即可。

下面比较关键的是CJKmainfont,这是为了显示中文,字体要指定为中文字体。

short-title是在原始的template中没有的,是需要在template在单独加上的。

---
title: Here is the long title
short-title: Short title
author: Shen, Chi
institute: Xi'an Jiaotong University
navigation: horizontal
date: July 16, 2020
CJKmainfont: Kaiti SC
classoption: aspectratio=43
output: 
  beamer_presentation:
    toc: true
    slide_level: 2
    theme: Madrid
    colortheme: default
    fonttheme: serif
    template: theme/template.tex
    highlight: tango
    includes:
      in_header: theme/header.tex
---

2 书写内容

这块就是用markdown的语法了,让pandoc去转换,不用去折腾LaTex语法了,具体的规则就很简单了,就是一级标题或者—用了区分每一页,具体的说明可以参加Rmarkdown

3 header里的内容

在header里我加入了学校的logo和计时器,具体内容如下:

% 设置计时器
\usepackage[font=Times, timeinterval=1.0, timeduration=15.0, timedeath=0, fillcolorwarningsecond=white!60!yellow]{tdclock}

\usepackage{graphbox}
\usepackage[absolute,overlay]{textpos}

% 设置计时器位置
\setbeamertemplate{background}{
    \rule{0em}{.99\paperheight}\hspace{19em}{
    \color{white}\initclock\tiny{\today}\bfseries\crono
    }
  }

% 首页加上logo
\titlegraphic{\includegraphics[height=1.2cm]{theme/logo.png}\hspace{0em}}

% 标题行加上logo
\setbeamertemplate{frametitle}
{\begin{beamercolorbox}[wd=\paperwidth]{frametitle}
      \strut\hspace{0.5em}\insertframetitle\strut
      \hfill
      \raisebox{-2mm}{\includegraphics[width=1cm]{theme/logo.png}}
    \end{beamercolorbox}
}

% 去掉标题的编号
\setbeamertemplate{section page}{
\centering
\begin{beamercolorbox}[sep=12pt,center]{part title}
  \usebeamerfont{section title}\insertsection\par
\end{beamercolorbox}
}


4 输出的结果

输出的方法就有很多了,RStudio里直接点个knit就可以了,VS Code的这个插件也是很方便,如果比较geek一点,在终端里直接pandoc也可以,下面是输出的结果,有点土,但是标题的位置、字体的大小、颜色,全部都在默认的theme里已经定义好了,完全就是按照学术ppt的样式,很省心,导出就直接是pdf,也不用考了兼容性的问题。

Figure 1

####



markdownbeamer Share Tweet +1