Ant-Veil

Caspar Blog

搞定 LaTeX Beamer 模板

| Comments

过一段时间公司和学校都得做 presentation,所以现在就得好好开始准备 slides。以前我就用 Beamer 做过一次 slide,而且是匆匆忙忙用了默认模板搞定的。这次借着再做 slides 的机会,我得自己搞个模板。

需求如下,非常简单:

1. 要在合适的位置打上 Logo(一般是左上角或者右上角);
2. 要能自定义页脚
3. 首页要有背景

经过半个白天加一个晚上的折腾,基本上解决了上述问题:

要打 Logo,并且自定义位置,可以使用如下语句:

 \logo{\pgfputat{\pgfxy(#1,#2)}{\pgfbox[center,base]{\includegraphics[height=0.5cm]{#3}}}}

事先要包含 pgf 宏包,#1,#2 是 Logo 坐标,#3 是 Logo 路径。关于坐标,我发现用 pdflatex 编译和用 xelatex 编译时坐标表示的实际位置是不同的,反正自己手工慢慢调就是了。也可以把上述代码加个\newcommand,做成一个带参数的命令直接调用。

自定义页脚,我参考了 beamer guide 和 beamer 里面的某个宏包的写法:

%% Custom footer
\usefoottemplate{
    \hbox{\tinycolouredline{structure}{
    \begin{beamercolorbox}[wd=0.22\paperwidth,ht=2.4ex,dp=1.2ex,left]{author in head/foot}%
        \usebeamerfont{author in head/foot}\insertshortauthor
    \end{beamercolorbox}%
    \begin{beamercolorbox}[wd=0.5\paperwidth,ht=2.4ex,dp=1.2ex,center]{title in head/foot}%
        \usebeamerfont{title in head/foot}\insertshorttitle
    \end{beamercolorbox}%
    \begin{beamercolorbox}[wd=0.28\paperwidth,ht=2.4ex,dp=1.2ex,right]{date in head/foot}%
        \usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{0.8em}
        \insertframenumber{} / \inserttotalframenumber\hspace*{4.5ex}
    \end{beamercolorbox}}}%
}

需要说明的是,我始终搞不懂\tinycolouredline 的第一个参数 structure 还能用什么代替,而且上述方案有个及其大的 BUG,在页脚最左边的那列的左边有 1em 的空白,如果要给这列填充了和那个空白区与不一样的背景色,就会很难看。我也没找到消除那列空白的代码。

首页加背景就太简单了,我直接用 wallpaper 宏包,然后在第一页加入:

\ThisCenterWallPaper{1}{inc/cover}

不管是加 Logo 也好,加墙纸也好,它们都很容易被 colortheme 中定义的背景色覆盖,这可以通过\setbeamercolor 来去掉背景色,基本语法如下:

\setbeamercolor{background canvas}{bg=}
\setbeamercolor{title}{fg=black, bg=lightgray!80!white}

最后放出模板,点此下载>>>>

Comments