惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
B
Blog
博客园_首页
云风的 BLOG
云风的 BLOG
S
SegmentFault 最新的问题
罗磊的独立博客
Jina AI
Jina AI
C
Check Point Blog
Martin Fowler
Martin Fowler
J
Java Code Geeks
博客园 - 司徒正美
美团技术团队
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
有赞技术团队
有赞技术团队
U
Unit 42
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
小众软件
小众软件

all models are wrong

-> Going both ways in R <- finding homologous probes using biomaRt Profiling in R More Segment HMMs Python and Numpy integers Nasty Python Things MICROCOSMOGRAPHIA ACADEMICA Pebl The Pirate Bay Trial
Latex, Beamer, Python, Beauty
mikedewar · 2009-02-26 · via all models are wrong

This post quickly shows how to create pretty latex beamer slides, that don’t look anything much like maths seminar slides, and  that can include well formatted (Python) code, as well as the normal stuff that Beamer is so good at (maths, videos, etc). I’m assuming you’ve got a `standard’ install of latex (by standard I mean: like mine) that includes beamer and the listings package. I’m also assuming that you already know how to use beamer, so I’ve not included all the documentclass junk and so on. Here’s a taster of what it looks like, how to do it is after the break:

beamer_screen

There are three things we need to do to make beamer slides like this that don’t look like those endless maths-y beamer slides that everyone seems to like for some reason.

  1. Get rid of all the junk on the top and the bottom! No-one can see it anyway!
  2. Make the colours of the presentation very pretty.
  3. Make the listings use a better font than courier, and also use pretty colours!

1: get rid of all the junk

This is an awesome command. It’s (maybe) the longest single command ever in the world, sort of like that village in Wales with the huge name:

/usetheme{default}
/beamertemplatenavigationsymbolsempty

So now, your beamer presentation is nice and clean and happy.

2: Make Pretty Colours

This is just like knowing the magic words. We define a colour, then we assign it to a magic word. So lets define three colours, a background, a foreground and a title colour:

/definecolor{fore}{RGB}{249,242,215}
/definecolor{back}{RGB}{51,51,51}
/definecolor{title}{RGB}{255,0,90}

These colours are awesome but obviously you can choose your own if you’re a philistine and disagree. I’ve chosen the names (like fore), but they can be whatever you like. You can use other colour specifications instead of RGB, though using RGB for a presentation makes sense to me because it’s probably never going to be read seriously on paper. Now we need to tell beamer to actually use them:

/setbeamercolor{titlelike}{fg=title}
/setbeamercolor{normal text}{fg=fore,bg=back}

there are millions of these magic words like ‘titlelike’ but no-one will tell you what they are.

3: Make the listings pretty!

To include code listing (like Python) we use the listings package because it’s brilliant. We need:

/usepackage{listings,bera}
/definecolor{keywords}{RGB}{255,0,90}
/definecolor{comments}{RGB}{60,179,113}
/lstset{language=Python,
keywordstyle=color{keywords},
commentstyle=color{comments}emph}

The packages are for the listsings (clearly) and bera is the font. It’s secretly Bitstream Vera but they had to change the name or something because the world is messed up! Anyway bera is a lovely font in my honest opinion and you should use this and not courier which is ugly and very last century.

The colours are for comments and keywords which you’ll see in a sec, be patient.

The funny lstset command tells the listings package some things. The first is that we’re using Python. There are other languages, I think, but why we wouldn’t be using Python is beyond me. Then we ask listings to make our keywords the colour we defined above (pink!) and our comments to be the comment colour and also emphasised!

Finally, we must make a sample page to demonstrate the lstlisting environment, and because there’s one more important thing that is NOT OBVIOUS! Here’s a sample page:

/begin{frame}[fragile]
/frametitle{A Page}
/begin{lstlisting}
def list_of_vectors(n,T):
 return [matlib.zeros((n,1)) for t in T]
/end{lstlisting}
 Here is an equation:
 /begin{equation}
 x_t = Ax_{t-1} + w_t
 /end{equation}
/end{frame}

The thing to note is the [fragile] command. Here’s what it does. It means that the weird error that happens if you don’t include it DOESN’T HAPPEN! Enjoy!