because LaTeX matters

includegraphics

Often, figures have a white background which makes the figure border invisible on white paper. If a figure has several disconnected elements, it looks better to delimit them with a frame around figure. The adjustbox package scales, resizes, trims, rotates, and also frames LaTeX content. Conveniently, these functions can be exported to the \includegraphics command, which is what I will show below.

Load the adjustbox package with the export option to make functions available to the \includegraphics command (graphicx package).

The WordPress logo was the first thing that came to my mind, I downloaded it from here (see the trademark policy for details on usage).

Changing the looks
Since everyone has different requirements in terms of looks, I will show how to make simple changes to the class file. Let’s assume we want to get rid of the logo and have a centered title (Memorandum) instead.

To Remove the logo simply delete the logo command. In fact, this works with all texMemo-specific commands. To add a title, however, we need to make a slight modification in the texMemo.cls file. First, open the class file with any text editor, ideally with your preferred LaTeX editor. Scroll all the way down to the last block (“% To, From, Subject Block”) and add the following code just before that:

{\begin{center}
\Large\bf
M\textsc{emorandum}
\end{center}}

It adds the word “Memorandum” as a centered title in bold small capitals. Save the class file. To see the result, use the sample code from the beginning and remove the \logo{} command.

Sample output of modified texMemo class.

The texMemo files can be downloaded as a compressed file from Rob’s website. The main file is the document-class: texMemo.cls. For illustration purposes, Rob provides some example tex-files with output.

I’ve been writing quite a bit of R code recently for my gene expression analysis. Also, I use Sweave (manual) which allows embedding R code “chunks” into TeX documents. When the code is being evaluated, the output (code, calculation results, plots, tables, etc.) will automatically integrated into the document as TeX syntax, making it an extremely handy tool for presentation and documentation purposes.
That said, I will now show how to get a better control of the size and placement of figures generated by Sweave code chunks by manually inserting them into a TeX document.

Let me first give a general Sweave example with a single plot and later extend it with a second, placing them side-by-side. The following code chunk defines a vector x and a function f.

Imagine now that we want to place plots of two functions, and , side-by-side using the subfig package. This cannot be done automatically, since there is no way to control the figure size in the final pdf directly from within the Sweave chunk. Therefore, we generate the figures and add them manually, giving us complete control of size, angle and trimming of the figure (see graphicx).

Basically, the code generates the plots (pdfs). We don’t want them to be automatically included into the document, which is achieved through the include=FALSE option. Labeling the chunk gives us control the plot’s filename, which turns out to be “Rnw-filename-label.pdf” (Rnw is a Sweave file extension). In case you prefer the figures not to have the filename of your source-file, there is a Sweave option that globally controls the figure-filename-prefix and the directory to which they are saved:

\SweaveOpts{prefix.string=<directory>/<filename-prefix>}

Finally, we manually add our plots using the standard LaTeX \includegraphics-command and the subfig-package (see this post for more details). In case you prefer png and/or eps figures, use the pdf, png, eps options:

The subfigure package was replace by the subfig package quite a while ago. I therefore decided to replace my old post on that topic (Placing figures/tables side-by-side with subfigure) with an introduction to the subfig package. The package simplifies the positioning, captioning (I wonder if that’s a word) and labeling of small “sub” figures and tables within a single figure or table environment.

So much for the theory, let’s have a look at the usage. First we load the package, the options tell LaTeX to include the subs in the listoffigures and listoftables. Most probably you will also need the graphicx package, e.g. to set the figure width.

\usepackage[lofdepth,lotdepth]{subfig}
%\usepackage{graphicx}

The subfloat command has a body, for the content, being most commonly a figure/table plus a label. The two optional arguments define the list-of-figures text and the caption. If only one is provided, the text will be used for both, somewhat similar to the caption command (\caption[⟨list entry⟩]{⟨caption⟩}).

\subfloat[⟨list entry⟩][⟨sub-caption⟩]{⟨body⟩}

We need the figure (or table) floating environment as a container for the actual subfigure/subtables. This leads us to a complete subfigure example with two subfloats:

The complete documentation of this very comprehensive package is available here.

A final remark:
In order to simulate figures for testing purposes, you may either use the draft option of the documentclass command which lets you load existing or non-existing figure files and draws an empty box as placeholder. Or you may make use of the rule command that by default draws a black line of a certain length and thickness.

Beamer is a LaTeX document class that provides extensive functionality to create presentations. Here, I will only show the basics and after reading this guide you will be able to create a simple presentation in LaTeX. I am aware there are a lot of tutorials available out there and this is not different from any other tutorial. I hope however, I can encourage some of you who have hesitated so far, for whatever reason, to create your next presentation with LaTeX. And I’m sure it will be a lot of fun, with similar effort. I should add that the output will obviously be a PDF file (with all its advantages!). Luckily, PDF-viewers (including Adobe Acrobat) provide a fullscreen-mode for presentation purposes.

So lets get started!

\documentclass{beamer}

Now that line is straight forward, not much to say about it. Once that’s done, we have to choose a theme. This website gives a visual overview of the most common themes. I like Singapore:

\usetheme{Singapore}

Next, still in the preamble, we prepare the title page, using a similar set of commands as for other document-classes:

A frame may have one or several slides. Since PDFs are static, dynamic “effects” such as adding more content to a frame are achieved by two consecutive slides in the output file.

We use the previously defined title page to create our first (single-slided) frame:

\begin{frame}
\titlepage
\end{frame}

Similar to articles, sections, subsections, etc. are available and can be used to define an outline, printed with \tableofcontents. For many themes, the outline will be displayed in the header/footer and provides direct access to a certain section of the presentation. Frame-titles are created using \frametitle{Title}.

Most of the time, a frame will show a list of items created through the well known itemize-environment:

Now what if you don’t want to show all the items at once, but one after another. The \pause-command will take care of it. Just add it anywhere you want to “pause” and will produce 3 slides. In presentation mode, the next bit of information is only shown after you press a key (usually space or arrow keys). So the above code example now looks as follows:

Finally, I will show you something a little more advanced. Two columns, with items on the left and figures on the right side. The idea is to show an item along with an image. We want one item after the other to appear, while the image replaces the previous. Let me give you the code first and then explain some of the details:

What’s new here is called overlay specification within an environment (itemize) and lets you display different text/content on different slides or a range of slides.

<1-> indicates that this item will be displayed from slide 1 onwards in this frame. We could also have used <1-3>. Whereas the actual figures will only be displayed on their specific slide, e.g. <1>.

If there is no environment, the set of things to display has to be enclosed by the overprint-environment: \begin{overprint}...\end{overprint}.

Another thing is the “overlay specification” for commands, e.g. to change the text-color for slides 2 and 3:

\color<2-3>[rgb]{1,0,0} This text is red on slides 2 and 3, otherwise black.

Here, the overlay specification always has to follow the command before any additional arguments. I have to admit, slightly useless, but at least it illustrates the result nicely (example was taken from the user guide page 81).

The following a complete code sample with a few frames containing the various examples described above: