Making Elegant Presentation Slides Using LaTex Beamer

This post demonstrates how to make elegant presentation slides using LaTex with Beamer package. If you are an Emacs user and haven’t read my previous posts about how to set up a nice LaTex working environment with Emacs on MacOS and Ubuntu, please have a look at it and I am pretty sure you’re gonna love it.

What’s Beamer

Beamer is a LaTeX document class for creating slides for presentations. With Beamer, it’s going to be much easier for us to create presentation slides using LaTex. Next, let me show you how to make elegant slides from scratch.

Create a LaTex Project

Fire a terminal and execute the following commands.

cd ~
mkdir -p example/pdf
cd example
mkdir bib
touch main.tex

In this example project, we create a folder example with two sub-folders pdf and bib in it. pdf contains all the figures you are including in the slides (we use pdf format for all the figures), and bib stores bibliography related files. The main source file main.tex is created in the root directory. Put the logo figures in the pdf sub-folder, and you should have a similar file tree as follows.

example/
├── bib
├── main.tex
└── pdf
    ├── CUHK_logo.pdf
    └── JHU_logo.pdf

Fire a text editor that you are comfortable with (e.g., Emacs). Copy and paste the following codes into the newly created main.tex file.

\documentclass[serif]{beamer}

% you can play with different themes and color themes to find your favorite combination.
\mode<presentation> {
  \usetheme{Luebeck}
  \usecolortheme{beaver}
  \beamertemplatenavigationsymbolsempty
  \setbeamertemplate{headline}{}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% include necessary packages here
\usepackage{graphicx} % for including images
\graphicspath{ {./pdf/} } % declare the path where your graphic files are
\DeclareGraphicsExtensions{.pdf} % so you won't have to specify these with every instance of \includegraphics
\usepackage{pgf} % for logo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% declare new command here
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% ----------------------------------------------------------
%	TITLE PAGE
% ----------------------------------------------------------

% The short title in [] appears at the bottom of every slide
% The full title is only on the title page
\title[short title \hspace{25mm}\insertframenumber/\inserttotalframenumber]{
Title
}

\author{Your name}

\institute{
  Your institution
  \medskip
  \textit{Your email address}
}

\date{\today} % Date, can be changed to a custom date

\logo{
  \pgfputat{\pgfxy(0,7.8)}{\pgfbox[right,base]
    {\includegraphics[width=1.2cm,height=1.2cm,keepaspectratio]{CUHK_logo}
      \hspace{\dimexpr\paperwidth-2.4cm-5pt}
      \includegraphics[width=.9cm,height=.9cm,keepaspectratio]{JHU_logo}}}
}

\begin{document}

\begin{frame}
  \titlepage % Print the title page as the first slide
\end{frame}

\logo{} % logo only appears on the first slide

% Table of contents slide, comment this block out to remove it
\begin{frame}
  \frametitle{Table of Contents}
  \fontsize{12}{10}\usefont{OT1}{phv}{bc}{n}\selectfont
  \tableofcontents
\end{frame}

% Throughout your presentation, if you choose to use \section{} and \subsection{} commands, these will automatically be printed on this slide as an overview of your presentation
\AtBeginSection[]{
  \begin{frame}
    \frametitle{Table of Contents}
    \fontsize{12}{10}\usefont{OT1}{phv}{bc}{n}\selectfont
    \tableofcontents[
    currentsection,
    sectionstyle=show/shaded,
    subsectionstyle=show/show/shaded,
    ]
  \end{frame}
}

\end{document}

Compile the project and you will see a PDF file with the following pages.

The second page is empty because we haven’t defined any sections or subsections. So let’s add more slides.

Include two more useful packages subfig and bm, and add more slides by copying the presentation slides code at the end of previous code block.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% include necessary packages here
\usepackage{graphicx} % for including images
\graphicspath{ {./pdf/} } % declare the path where your graphic files are
\DeclareGraphicsExtensions{.pdf} % so you won't have to specify these with every instance of \includegraphics
\usepackage{pgf} % for logo
\usepackage{subfig}
\usepackage{bm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% ----------------------------------------------------------
%	PRESENTATION SLIDES
% ----------------------------------------------------------

\section{section A}

\subsection{subsection B}
\begin{frame}\frametitle{title D}
  \begin{figure}
    \centering
    \includegraphics[height=.7\textheight]{example-image}
    \caption{This is the caption.}
  \end{figure}
\end{frame}

\section{section C}

\subsection{subsection D}
\begin{frame}\frametitle{title E}
  \begin{figure}
    \centering
    \subfloat[First subfigure\label{fig:a}]{\includegraphics[height=2cm,width=3cm]{example-image}}\qquad
    \subfloat[Second subfigure\label{fig:b}]{\includegraphics[height=2cm,width=3cm]{example-image-a}}
    \caption{A figure}
    \label{fig:1}
  \end{figure}
  \begin{figure}
    \centering
    \subfloat[Third subfigure\label{fig:c}]{\includegraphics[height=2cm,width=3cm]{example-image-b}}\qquad    
    \subfloat[Fourth subfigure\label{fig:d}]{\includegraphics[height=2cm,width=3cm]{example-image-c}}
    \caption{Another figure}
    \label{fig:2}
  \end{figure}
\end{frame}

\begin{frame}\frametitle{title F}
  \begin{align}
    \mathbf{H}(\bm{\theta}(t)) \ddot{\bm{\theta}}(t) + \mathbf{C}(\bm{\theta}(t),\dot{\bm{\theta}}(t)) + \mathbf{G}(\bm{\theta}(t)) = \bm{\tau}
  \end{align}
\end{frame}

After compilation, you can obtain some elegant slides as follows.

Enjoy playing with Beamer.

Thanks for reading!

Setting Up a Nice Environment for LaTex on Ubuntu

This post is similar with the previous one for MacOS, and this one demonstrates how to configure a nice LaTex working environment with Emacs on Ubuntu.

Prerequisites

Install AucTex Package for Emacs

AucTex can be easily installed by using the Emacs package manager.

M-x list-packages RET

Mark the AucTex package for installation with i, and execute the installation by hitting x. If you encounter any issue during the previous step, please check your configuration for the package manager in your init file.

Configure your Emacs

Once you finish installing the packages mentioned above, you are ready to configure your Emacs by putting following configurations into your emacs init file.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; setting up latex mode
;; Forward/inverse search with evince using D-bus.
;; Installation:
;; M-x package-install RET auctex RET
(add-hook 'LaTeX-mode-hook 'TeX-PDF-mode)
(add-hook 'LaTeX-mode-hook 'TeX-source-correlate-mode)
(setq TeX-source-correlate-method 'synctex)

(if (require 'dbus "dbus" t)
    (progn
      ;; universal time, need by evince
      (defun utime ()
	(let ((high (nth 0 (current-time)))
	      (low (nth 1 (current-time))))
	  (+ (* high (lsh 1 16) ) low)))

      ;; Forward search.
      ;; Adapted from http://dud.inf.tu-dresden.de/~ben/evince_synctex.tar.gz
      (defun auctex-evince-forward-sync (pdffile texfile line)
	(let ((dbus-name
	       (dbus-call-method :session
				 "org.gnome.evince.Daemon"  ; service
				 "/org/gnome/evince/Daemon" ; path
				 "org.gnome.evince.Daemon"  ; interface
				 "FindDocument"
				 (concat "file://" pdffile)
				 t     ; Open a new window if the file is not opened.
				 )))
	  (dbus-call-method :session
			    dbus-name
			    "/org/gnome/evince/Window/0"
			    "org.gnome.evince.Window"
			    "SyncView"
			    texfile
			    (list :struct :int32 line :int32 1)
			    (utime))))

      (defun auctex-evince-view ()
	(let ((pdf (file-truename (concat default-directory
					  (TeX-master-file (TeX-output-extension)))))
	      (tex (buffer-file-name))
	      (line (line-number-at-pos)))
	  (auctex-evince-forward-sync pdf tex line)))

      ;; New view entry: Evince via D-bus.
      (setq TeX-view-program-list '())
      (add-to-list 'TeX-view-program-list
		   '("EvinceDbus" auctex-evince-view))

      ;; Prepend Evince via D-bus to program selection list
      ;; overriding other settings for PDF viewing.
      (setq TeX-view-program-selection '())
      (add-to-list 'TeX-view-program-selection
		   '(output-pdf "EvinceDbus"))

      ;; Inverse search.
      ;; Adapted from: http://www.mail-archive.com/auctex@gnu.org/msg04175.html
      (defun auctex-evince-inverse-sync (file linecol timestamp)
	(let ((buf (get-file-buffer (substring file 7)))
	      (line (car linecol))
	      (col (cadr linecol)))
	  (if (null buf)
	      (message "Sorry, %s is not opened..." file)
	    (switch-to-buffer buf)
	    (goto-line (car linecol))
	    (unless (= col -1)
	      (move-to-column col)))))

      (dbus-register-signal
       :session nil "/org/gnome/evince/Window/0"
       "org.gnome.evince.Window" "SyncSource"
       'auctex-evince-inverse-sync)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Finally

Yes! That’s it. You’re all set. Open a .tex file and give it a try. Once you finish editing the source file, you can compile the project with C-c C-c and C-c C-c again to view the PDF in Evince. Forward search can be called by C-c C-v and inverse search can be called by ctrl+(left click).

Thanks for reading!