LaTeX – The Ulyssis Workshop (part 2)

Last time I introduced the very basics of LaTeX after a workshop organised by Ulyssis, which you can find here. As I promised earlier, today I will talk you through the code to insert tables and figures into your text. For those of you who want to really impress their peers, I will also explain how you can format two figures next to each other (which required some serious googling skills on my behalf). But let’s get started with the basics first.

You can add your table within a \part{Title goes here}, \section{Subtitle goes here}, or \subsection{Subsubtitle goes here} of your \begin{document}, but before your \end{document}. There are several kinds of tables, the most basic one starts by \begin{tabular}{c c c} to specify that you want three columns, and for each row you add item & item & item \\ to fill in the three columns. After you added several rows, don’t forget to \end{tabular}.

For your fancy table you \begin{table}[h] right here, but you want it in the \begin{center} and then you can \begin{tabular}{c c c} with some columns, which you know how to fill in by now (item & item & item \\ for each row). After you \end{tabular}, you add a \caption{fancy table}, you \end{center} and finally, you \end{table}. Once you understand the basics, you can make your life easier by creating your tables in a tool such as http://www.tablesgenerator.com/.

Now in order to add figures to your document, you need to add a package in your preambula – the thing that comes right after \documentclass[11pt]{article} at the start of your document. You can \usepackage{graphicx} to insert some fancy figures. Of course you need to save your picture in the same folder as your .tex file, otherwise it might be hard to find. Now you’re ready to \begin{figure} and \includegraphcs[width=0.5\textwidth]{your figure}, where you define the width of your figure, in this case 50%, but you could also set [width=100mm] to include a figure of 10 cm wide. To center your figure you can use the \centering command, and adding a \caption{your figure} works the same as for tables. Again you need to \end{figure} before you start with the rest of your text.

If you want two figures side by side (or even three, but you can probably figure it out if you understand the mechanism), stackexchange comes to the rescue. Because you need a specific type of \caption, you need to add another package in your preambula called \usepackage{caption}. So again you \begin{figure} by \centering both your figures in the middle of the page. But you now split your figure into two \begin{minipage}{.5\textwidth} each taking up 50% of the width of your page. In order for each figure to look spot on, you should use \centering again, then \includegraphics[width=0.9\linewidth]{first image}. In this case the linewidth for each figure takes up only half of the page, so the 90% used here, actually means you have a 10% margin between this figure and the next. In this case, you need the \captionof{figure}{This figure} to add a caption to the first figure. If you want to refer to your figure in the text you can always add a \label{fig:figure1} and inside your text \ref{fig:figure1} so that the number of the figure is always correct, even if you add other figures. Now you need to \end{minipage} number one, and in order for the two minipages to appear next to each other, you need a % inbetween. Now you can repeat the \begin{minipage}{.5\textwidth} process to add one more figure, and after you \end{minipage}, also \end{figure}.

So there you go, the perfect tables and figures to impress any reader! Next time, I will explain how to add your citations and bibliographic references, BiBTeX style.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s