Klicka här för att använda ShareLaTeX på Engelska

To see the corresponding video for this blog post click here.

In the last post we looked at adding some basic content into our presentation. In this post we’re going to look at adding some other types of content.

## Blocks

One of the ways beamer lets us display information on slides is using ‘blocks’. To do this we use the ‘block’ environment.

\begin{block}{Block Title}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\end{block}


At the end of the begin command we simply enter the block’s title in curly brackets. Then whatever we enter in between the begin and end commands, forms the content of the block. This is what it looks like:

There are quite a few variations of the block environment that help us produce blocks for different purposes. The first is the ‘alertblock’ environment which is similar to the block environment except its colour is red instead of blue.

\begin{alertblock}{Block Title}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\end{alertblock}


Then there’s the definition environment which produces a standard blue block but with the title already specified as ‘definition’.

\begin{definition}
A prime number is a number that...
\end{definition}


Next there’s the example environment which produces a green block with the title ‘Example’.

\begin{example}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\end{example}


There is also a group of blocks that are especially useful for presenting mathematics. For example the ‘theorem’ environment, the ‘corollary’ environment and the ‘proof’ environment.

\begin{theorem}[Pythagoras]
$a^2 + b^2 = c^2$
\end{theorem}
\begin{corollary}
$x + y = y + x$
\end{corollary}
\begin{proof}
$\omega +\phi = \epsilon$
\end{proof}


The theorem and corollary environments automatically put their content in italics. These two also allow us to add extra content to the block title in parenthesis by adding text into square brackets at the end of the begin command. It’s worth mentioning at this point that beamer automatically loads the amsmath package so you can add more complicated mathematics straight away.

## Code

Now let’s talk about adding code into slides. This is particularly important for any computer science related presentation. To do this we use the ‘semiverbatim’ environment. In order to use this environment on a frame, we need to add the ‘fragile’ option into the \begin{frame} command. Now whatever text we enter in the environment will appear as written, except for the backslash, open curly bracket and close curly bracket characters, which will continue to behave as they normally would in LaTeX. Therefore if we want to print some code which includes these characters we need to add an extra backslash before each of them. Here’s an example printing the code we used for the title slide.

\begin{frame}[fragile]
\frametitle{Including Code}
\begin{semiverbatim}
\\begin\{frame\}
\\frametitle\{Outline\}
\\tableofcontents
\\end\{frame\}
\end{semiverbatim}
\end{frame}


Finally I want to discuss adding hyperlinks to our presentation. Before we can create any hyperlinks we need to tag the frames we want to link to using the \label command. For example, we’ll add a label to the contents frame, the columns frame and the pictures frame. E.g.

\begin{frame}
\label{contents}
...


Then we use the \hyperlink command to insert a link.

\hyperlink{contents}{click here}


In the first set of curly brackets we enter the label of the target frame and in the second set we add the text that we want to be clickable. Now if we compile the document you’ll see the text is now a clickable link. Beamer also allows us to use buttons. To do this we simply add a button command into the second set of curly brackets. For example, we’ll swap the ‘click here’ text for the \beamerbutton command and enter in curly brackets the text we want to appear on the button.

\hyperlink{contents}{\beamerbutton{contents page}}


Here are some other button commands we can use.

\hyperlink{columns}{\beamergotobutton{columns page}}

\hyperlink{pictures}{\beamerskipbutton{pictures page}}

\hyperlink{pictures}{\beamerreturnbutton{pictures page}}


The beamer go to button, the beamer skip button and the beamer return button.

This concludes our second discussion on adding content to our presentation. In the next post we’ll look at animating our presentations. Please do keep in touch with us via Facebook, Twitter & Google+.

pt 1 - Getting Started

pt 2 - Lists, Columns, Pictures, Descriptions & Tables

pt 4 - Overlay Specifications

pt 5 - Themes and Handouts

Posted by Josh Cassidy on 16 Aug 2013

## About Us

ShareLaTeX is an online LaTeX editor that allows real-time collaboration in your browser

View All