I started switching full-time to Ubuntu (once again) a couple of weeks ago. Turns out, it’s in much better condition than when I last tried it. Anyway, one of the problems was finding a replacement for Powerpoint. I hate creating presentations for classes — in fact, I think they’re counter-productive — but I have no choice for the moment. So, I decided to give LibreOffice Impress a chance. That was an hour of my life down the drain. Finally, I returned to beamer. Of course, I had to write my own theme because I couldn’t use the same theme used by all the rest of the world. To cut this long and boring story short, I tried very hard to find a tutorial on writing beamer themes, couldn’t do so, learned it through experiment and decided to write the tutorial myself. Here is that tutorial.
This is a beamer newbie tutorial, not a LaTeX newbie tutorial. You should be somewhat comfortable with LaTeX before you can understand this stuff. Also, most of the “techniques” I use here will be frowned upon by LaTeX gurus and I know they’re not the “right” approaches but they get the job done and I will be refactoring this when I get time to adopt the best practices. This tutorial just aims to help you write your own themes in the hope that more and more beamer templates will be created and people will stop using the blue rounded-corner-box theme that beamer has become associated with.
Here’s the final result we’re trying to produce. (This is the beamer-tutorial tag on my github project titled latex-templates. Notice that the template in the github tree might have changed since the writing of this tutorial as I’m continually modifying the code to better suit my workflow. I created the beamer-tutorial tag specifically for this tutorial — as the name implies. All links in this tutorials are supposed to point to files in this tag.)
Let’s begin. Firs, get the tutorial files here. Download the beamer-tutorial.zip and extract it.
The two important files are the following:
The source file is in: doc-prep-latex/sources/slideset01.tex
Include file is in: includes/header-commands.tex
There are three sections that you need to define to get a basic custom beamer template.
First, we want to define some custom fields that will be used throughout our files. (I know this isn’t the proper method of defining custom fields but it’s the only one I’m comfortable with.) I will refer to github links but you can see the same thing in your downloaded files. In the slideset01.tex file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Let’s begin by looking at how we’ve modified the title page. Notice, first that we’re including the header file just after the definitions above.
This will ensure that we have the stuff included in this location. The way I’ve set this up, the title page will get created automatically and the body will start. The code for that can be seen in includes/header-commands.tex:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
A little explanation of what’s going on here. This should help you customize the theme depending on your needs. The line numbers in code below refer to the actual file. (Refer to the complete file for reference. We’ll be jumping around a bit.)
Line 102 sets the footline (that’s the footer) to empty. This makes the page numbers etc disappear.
Line 103 begins the first frame (slide).
Lines 104-113 set the title and author etc. Pretty basic stuff.
Line 114 inserts the logo. See the pre-reqs section above to see where the logo image comes from.
Lines 117-127 typeset the title of the presentation, author etc. Again, it’s pretty straight-forward if you know a bit of LaTeX. The only complication might be the if statements. It’s basically saying that if we have a non-empty subtitle, put a colon after the title, insert a linebreak and put the subtitle, otherwise, skip the colon and the subtitle.
Line 130 hides the navigation symbols from this point onwards i.e. they won’t appear on slides other than the title.
We have another little fix that we need to do to finish off the title page and that is the definition of the header for it.
Header for Slides
So, we have two types of headers: (a) for the title page and (b) for subsequent pages.
The title header gets defined as:
1 2 3 4 5 6 7 8 9
We basically redefine the headline template to be a a box! It’s a thin, tall box that just sits on the left edge. It’s created using the beamercolorbox environment with 50ex height, 2.25ex width and the color headbarcolor (Line 54). It has no text (Line 56). Finally, we add a -50ex vertical space so that the text that follows will not get displaced because of this box. (Try getting rid of this line to see where the title goes.)
The second headline we need to define is for subsequent pages.
1 2 3 4 5 6 7 8 9 10 11 12
This very similar to the first headline. The only difference is that the box is much shorter (10ex). Same trick with the negative vertical space. Notice that we have not actually inserted the frame title. Beamer will take care of that automatically for us. We’re just redefining the headline.
We’re also increasing the line spacing for our subsequent slides (Line 145).
Finally, let’s get to the footer.
The footer is going to be defined using the same technique of placing boxes with some information in them this time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
Lines 62-67 define some colors — basically shades of gray.
Linex 71-88 insert some boxes. Most of them are empty and there for design. We do, however, put the slidesettitle with a small fontsize in the first box (Lines 73-74) and the author’s web address in another box (Lines 81-82). We also put the page numbers in the last box (Line 87). If you can get over all the boxes, this is not that complicated.
Finally, we put a vspace (Line 91) at the end to separate the footer from the lower edge of our slide.
Some Comments Our slides file now works on this theme and every LaTeX command will work as usual. Maybe I should’ve done some renewcommand’s to get a .sty file but that will have to wait for another day. If someone reading this tutorial can help out with that, fork the project on github, make the changes and send me a pull request.