Beamer

介绍

Beamer是一个生成演示稿的 LaTeX 环境. 它包括了以下特性:

  • 在演示稿中自动生成结构化的元素(例如 Marburg 主题)。 在演示稿中,这个特性可以为观众提供了视觉参考。
  • 对组织演示稿有很大的帮助。
  • 主题
  • 完全支持 LaTeX

优点

在 Org 模式中用 Beamer 有很多好处,Beamer的优点,很多都继承自org:

  • 写作效率高,用org模型写beamer,熟悉之后,发现效率会明显提高很多,不 用费心思去安排格式排版。
  • 和org模式兼容,用org模式写的论文等文章,可以方便的copy出来,写幻灯片。
  • Org 模式很简单,语法通常更容易使用,可以不关注排版,更关注写作内容。排版出来的效果又很惊 艳。Beamer的各种模版制作出来的幻灯片也有很好的效果。
  • 与 org-babel 绑定在一起,实时语法高亮源码和内嵌结果。
  • 对代码段的支持很好

安装配置

安装latex

我的环境是macos,在mac上,安装的时候,先到latex的网站下载镜像, MacTex官网下载地址是,http://www.tug.org/mactex/mactex-download.html 下载后直接点击安装即可。

安装代码支持

代码高亮支持,建议使用minted。使用minted需要安装python环境,以及 Pygments模块,因为minted依赖于该模块提供超过300种语言的语法高亮。 Pygments建议直接到官网下载whl包,直接用以下命令安装

brew install Pygments-2.15.1-py3-none-any.whl

minted支持很多代码显示效果,可以到网上查看效果,常见的有以下几种

  • manni
  • vs
  • pastie
  • autumn
  • emacs
  • tango
  • rrt
  • manni

配置

emacs配置

emacs中的配置如下,注意要引入ox-beamer包。

(require 'ox-beamer)
;;--------------------------begin latex---------------------------
(with-eval-after-load 'ox-latex
    (add-to-list 'org-latex-classes
        '("ctexart"
          "\\documentclass[UTF8,a4paper,12pt]{ctexart}
          \\setcounter{secnumdepth}{4}
          \\usepackage[linkcolor=blue,citecolor=blue,backref=page]{hyperref}
          \\hypersetup{hidelinks}
          \\usepackage{xeCJK}
          \\usepackage{color}
          \\usepackage{xcolor}
          \\usepackage{fontspec}
          \\usepackage{geometry}
          \\geometry{top=2cm,bottom=2cm,right=2cm,left=2.5cm}
          \\geometry{headsep=0.5cm}
          \\usepackage{setspace}
          \\setlength{\\baselineskip}{22pt}
          \\setlength{\\parskip}{0pt}
          \\usepackage{enumerate}
          \\usepackage{enumitem}
          \\newcommand{\\xiaosan}{\\fontsize{15.1pt}{\\baselineskip}\\selectfont}
          \\newcommand{\\sihao}{\\fontsize{14.1pt}{\\baselineskip}\\selectfont}
          \\newcommand{\\xiaosi}{\\fontsize{12.1pt}{\\baselineskip}\\selectfont}
          \\newcommand{\\wuhao}{\\fontsize{10.5pt}{\\baselineskip}\\selectfont}
          \\setenumerate[1]{itemsep=0pt,partopsep=0pt,parsep=\\parskip,topsep=5pt}
          \\setitemize[1]{itemsep=0pt,partopsep=0pt,parsep=\\parskip,topsep=5pt}
          \\setdescription{itemsep=0pt,partopsep=0pt,parsep=\\parskip,topsep=5pt}
          \\usepackage[super,square,numbers,sort&compress]{natbib}
          \\usepackage{minted}
          \\usemintedstyle{manni}%{vs}%{pastie}%{autumn}%{emacs}%{tango}%{rrt}%{manni}
          \\usepackage{fancyhdr}
              \\pagestyle{plain}
          \\usepackage{titlesec}
             \\titleformat{\\section}[block]{\\normalfont\\xiaosan\\bfseries\\heiti}{\\thesection}{10pt}{\\xiaosan}
             \\titleformat{\\subsection}[block]{\\normalfont\\sihao\\bfseries\\heiti}{\\thesubsection}{10pt}{\\sihao}
             \\titleformat{\\subsubsection}[block]{\\normalfont\\sihao\\bfseries\\heiti}{\\thesubsubsection}{10pt}{\\sihao}
              \\titlespacing{\\chapter} {0pt}{-22pt}{0pt}{}
              \\titlespacing{\\section} {0pt}{0pt}{0pt}
              \\titlespacing{\\subsection} {0pt}{0pt}{0pt}
              \\titlespacing{\\subsubsection} {0pt}{0pt}{0pt}"
           ("\\section{%s}" . "\\section*{%s}")
           ("\\subsection{%s}" . "\\subsection*{%s}")
           ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
           ("\\paragraph{%s}" . "\\paragraph*{%s}")
           ("\\subparagraph{%s}"     . "\\subparagraph*{%s}")))
    (add-to-list 'org-latex-classes
     ;; beamer class, for presentations
        '("beamer"
        "\\documentclass[11pt,professionalfonts]{beamer}
         \\mode
          \\beamertemplateballitem
          \\setbeameroption{show notes}
          \\usepackage{graphicx}
          \\usepackage{tikz}
          \\usepackage{xcolor}
          \\usepackage{titletoc}
          \\usepackage{ctex}
          \\usepackage{xeCJK}
          \\usepackage{amsmath}
          \\usepackage{lmodern}
          \\usepackage{polyglossia}
          \\usepackage{verbatim}
          \\usepackage{minted}
          \\usepackage{soul}
          \\usepackage{textcomp}
          \\usepackage{marvosym}
          \\usepackage{wasysym}
          \\usepackage{latexsym}
          \\usepackage{amssymb}
          \\usepackage{/Users/lhl/org/styles/zyuebeamer}
          \\subject{{{{beamersubject}}}}"
              ("\\section{%s}" . "\\section*{%s}")
              ("\\begin{frame}[fragile]\\frametitle{%s}"
               "\\end{frame}"
               "\\begin{frame}[fragile]\\frametitle{%s}"
               "\\end{frame}")))
    (add-to-list 'org-latex-packages-alist
                 '("UTF8,fontset=macnew" "ctex" t ))
    (setq org-latex-default-class "ctexart")
    ;; (setq org-latex-logfiles-extensions
    ;;       (quote ("lof" "lot" "tex~" "tex" "aux"
    ;;               "idx" "log" "out" "toc" "nav"
    ;;               "snm" "vrb" "dvi" "fdb_latexmk"
    ;;               "blg" "brf" "fls" "entoc" "ps"
    ;;               "spl" "bbl" "xdv")))
    (setq org-latex-listings 'minted)
    (setq org-latex-minted-options
        '(("framesep" "2mm")
          ("baselinestretch" "1.2")
          ("linenos=true")
          ("fontsize" "\\footnotesize") ;
;;            ("bgcolor" "LightGray")
          ("breaklines" "true")
          ("breakanywhere" "true")
          ))

    (setq org-latex-pdf-process '("xelatex -shell-escape -interaction nonstopmode %f"
                                  "xelatex -shell-escape -interaction nonstopmode %f"))
)
;;\\ctexset{section={format=\\raggedright \\sihao \\heiti}} ;标题靠左
;;\\usepackage[super,square,numbers,sort&compress]{natbib}  ;引用标号
;; \\usepackage{amssymb}  ;数学公式包
;; \\usepackage{mathrsfs} ;数学公式包
;; \\usepackage[namelimits]{amsmath} ;数学公式包
;; \\usepackage{tikz}  ;绘图包,流程图,脑图
;; \\setmainfont{Times New Roman} ;全局设置字体
;; \\usepackage{ulem} ;下划线等标记
          ;; \\usepackage{fancyhdr} ;设置页眉页脚
          ;;     \\pagestyle{fancy}
          ;;     \\fancyhead{}
          ;;     \\fancyhead[CO,CE]{\\leftmark}
;;          \\institute{{{{beamerinstitute}}}} 指定学校

snippet配置

snippet中,可以定义一个beamer模版,方便创建beamer文件头,如下:

# -*- mode: snippet -*-
# name: beamer
# key: <beamer
# --
#+TITLE:     $1
#+AUTHOR:    name
#+EMAIL:     name@xxx.com
#+DESCRIPTION:
#+KEYWORDS:
#+OPTIONS:   H:2 num:t toc:t \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS:   TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+startup: beamer
#+LaTeX_CLASS: beamer
#+LaTeX_CLASS_OPTIONS: [bigger]
#+columns: %45ITEM %10BEAMER_env(Env) %10BEAMER_act(Act) %4BEAMER_col(Col) %8BEAMER_opt(Opt)

基础用法

列表,表格,链接,标签

列表、表格、链接、标签等等所有的编辑功能,都跟org模式完全一样,区别是每个三级标题下的内容,注意 不要写的过多,否则显示效果不好。

二级标题构成一个幻灯片,一级标题构成大纲。三级标题可以构成colum,block 等。

属性设置

属性设置都以:PROPERTIES:开始,以:END:结尾,中间可以填入不同的设置项, 具体参数见下图。

  • BEAMER_col 控制列宽度,0.5表示一半宽度。

  • BEAMER_env 控制列外观,值可以是 ignoreheading 、 block 等等。

  • BEAMER_envargs 可以控制列对齐,默认是中间对齐,改成顶部对齐的值为 C[t] ;设置为 <2-> 之类的值,可以控制停顿。

根据官方文档的描述,其他属性的用处如下:

If ‘BEAMER_ENV’ is set to ‘appendix’, Org exports the entry as an appendix. When set to ‘note’, Org exports the entry as a note within the frame or between frames, depending on the entry’s heading level. When set to ‘noteNH’, Org exports the entry as a note without its title. When set to ‘againframe’, Org exports the entry with ‘\againframe’ command, which makes setting the ‘BEAMER_REF’ property mandatory because ‘\againframe’ needs frame to resume.
When ‘ignoreheading’ is set, Org export ignores the entry’s headline but not its content. This is useful for inserting content between frames. It is also useful for properly closing a ‘column’ environment.
When ‘BEAMER_ACT’ is set for a headline, Org export translates that headline as an overlay or action specification. When enclosed in square brackets, Org export makes the overlay specification a default. Use ‘BEAMER_OPT’ to set any options applicable to the current Beamer frame or block. The Beamer export back-end wraps with appropriate angular or square brackets. It also adds the ‘fragile’ option for any code that may require a verbatim block.
To create a column on the Beamer slide, use the ‘BEAMER_COL’ property for its headline in the Org file. Set the value of ‘BEAMER_COL’ to a decimal number representing the fraction of the total text width. Beamer export uses this value to set the column’s width and fills the column with the contents of the Org entry. If the Org entry has no specific environment defined, Beamer export ignores the heading. If the Org entry has a defined environment, Beamer export uses the heading as title. Behind the scenes, Beamer export automatically handles LaTeX column separations for contiguous headlines. To manually adjust them for any unique configurations needs, use the ‘BEAMER_ENV’ property.

分列布局

分列布局,在beamer中有个熟悉设置方式,如下

:PROPERTIES:
:BEAMER_env: column
:BEAMER_col: 0.3
:END:

通过以上参数设置,可以指定列宽为0.3页面宽度。在org中,可以使用快捷建 C-c C-n 选择需要的属性,文档中会自动插入以上代码。

注意,有时候快捷键不起作用,原因未知。 可以参考网上的说法,试试效果

有一点小小的不爽,在扩展beamer snippet之后,要在第一行 startup: beamer 上做 C-c C-c ,才能使 C-c C-b 组合键起作用。

建议以上各种属性都实验一下。

block布局

block布局是beamer中一个很有用的功能。可以在幻灯片中写出不同显示效 果的块,块同样可以指定宽度,如下

:PROPERTIES:
:BEAMER_env: block
:BEAMER_col: 0.6
:END:

BEAMER_ACT

beamer_act可以控制这一帧的显示顺序。pdf中,是通过生成多张页面,显示的 时候重叠起来。

BEAMER_act: [<+->]

如果需要三个block按先后顺序显示,可以用以下方式

:PROPERTIES:
:beamer_act: <1>
:BEAMER_col: 0.3
:BEAMER_ENV: block
:END:
a picture link

:PROPERTIES:
:beamer_act: <2->
:BEAMER_col: 0.3
:BEAMER_ENV: block
:END:
b picture link

:PROPERTIES:
:beamer_act: <3->
:BEAMER_col: 0.3
:BEAMER_ENV: block
:END:
c picture link

其中,a图片显示后,在后续b图显示出来时会消失,但b,c一直存在。

no indent list

#+ATTR_BEAMER: :environment nonindentlist

  • item 1, not indented
  • item 2, not indented
  • item 3, not indented

colorbox

#+LaTeX: \setbeamercolor{myblockcolor}{bg=magenta,fg=white}
* myblockcolor :B_beamercolorbox:
:PROPERTIES:
:BEAMER_env: beamercolorbox
:BEAMER_opt: wd=6cm,rounded=ture,center
:END:

可以指定特殊的颜色。

进阶功能

安装beamer模版

beamer 有很多默认的模版,各模版的显示效果可以从这个网站查看。 https://hartwork.org/beamer-theme-matrix/

大部分情况下,使用默认的模版,效果就已经足够满意了。如果自己有定制效果, 可以自己修改模版,或者从网上查找模版。

下载的模版大都是sty文件类型,可以下载这个sty文件和相关的依赖文件,放到 写beamer文档的目录下,写的时候引入包即可。可以在.emacs配置文件中引用这个模版。具体 配置方式参考下一节。