A LaTeX Course for UoA Students
 A HTML version Instructor: Theo J. Mertzimekis
 Home > Examples
 » First Steps » Basic Commands » Math equations » Thesis template » Bibliography » Examples » Useful Links

University of Athens

 Examples

Some objects LaTeX deals with are found quite often in scientific and other documents. Most common ones are Tables and Figures. I will provide a few simple examples on how to include such objects in a LaTeX documents, especially in the thesis template we are dealing with (the corresponding LaTeX file includes these examples as well)

Tables

Tables are essential when we present groups of data or some organized set of information. A Table in LaTeX is a special object belonging to the family of "Floats", same as Figures. Floats can be placed at specific places on a page, be aligned or rotated, have a caption and a label to refer to in the text. A simple example of a 3x3 table without borders and center alignment is given below.

A table has rows and columns. Only the number and alignment of columns need to be stated explicitly at the beginning, while we can have as many rows we like. Rows and columns make table cells, which are separated by putting the special character & inbetween. In the example below, see the first row: R. Feynman & 1 & 2 \\. The very left cell is "R. Feynman", then the next one ("1") starts after the & character, and so happens for the right cell ("2"). We state the end of the row and beginning of a new one in the table with the \\ combo, similarly to normal linebreak in text.

The command \caption{...} provides the table legend and can be placed at the bottom of the table if placed after the tabular environment, or at the top if it precedes it.

The \label command gives an ID to the table so that we would be able to refer to it from any place in the text. LaTeX will keep track of these IDs and sort them out automatically during compilation. It is the same for all floats, figures too, that have a label. LaTeX is also able to distinguish between different types of floats and keeps their individual numbering in order.

\begin{table}[ht]    ← start table environment
\begin{tabular}{ccc}    ← start tabular environment
R. Feynman & 1 & 2 \\    ← row #1
P. Higgs & 3 & 4 \\    ← row #2
L. Botzmann & 5 & 6    ← row #3
\end{tabular}    ← end tabular environment
\caption{A $3\times 3$ table with center alignment and no borders}    ← table caption
\label{tab:no1}    ← label of the table
\end{table}    ← end table environment

Here is a slightly modified example. I have left-aligned the left column and added a single border line between the first and second columns. Also, the table is now centered in the page (left-right) with the command \centering, which is similar to the center environement mentioned earlier. In both cases, the table has the option [ht], which says the table should be placed [h]ere and [t]op of the page if possible.

\begin{table}[ht]
\centering
\begin{tabular}{l|cc}
R. Feynman & 1 & 2 \\\hline
P. Higgs & 3 & 4 \\\hline
L. Botzmann & 5 & 6
\end{tabular}
\caption{A $3\times 3$ table - second example}
\label{tab:no2}
\end{table}

A last example shown here creates a table with rows spanning multiple columns. I only show you the tabular environment.

\begin{tabular}{|l|l|}    ← print vertical borders between left-aligned data in columns
\hline    ← a horizontal borderline
\multicolumn{2}{|c|}{Scientist roster} \\    ← define 2 columns for one row
\hline    ← a horizontal borderline
1 & A. Einstein \\    ← row #1
2 & J.J. Thomson \\    ← row #2
3 & E. Rutherford \\    ← row #3
4 & M. Curie \\    ← row #4
5 & R. Feynman \\    ← row #5
\hline    ← a horizontal borderline
\end{tabular}

There are several more options for tables (see e.g. packages rotating, multirow) that one can use.

Figures

The second important object for scientific reports is figures. It may be data graphs, advanced infographics or even pictures. They can all be handled effectively by the figure environment, often assisted by additional packages. I recommend the graphicx package that I will use in the following example.

The figure is a float for LaTeX, similar to tables. It can support labels and captions as well. A list of figures can be printed at the beginning of the report we are describing with the command \listoffigures. Here are some examples on how to use figures.

\usepackage{graphicx}
...
\includegraphics[width=60mm]{uoa_logo}
...

I have defined the use of package graphicx in the preamble, then at the point I want to add an image file (here "uoa_logo.png" skipping the extension .png) I use the command \includegraphics[width=60mm]{uoa_logo}, setting the width of the image equal to 60mm. With this package, I can include PDF, JPG and PNG images in the document. If I need to include Encapsulated PostScript Images (EPS), then I need to load a different package in the preamble (\usepackage{epsfig}) that has its own properties.

I have used no alignment and also skipped entirely the float \begin{figure}. This simply means I will add the picture in the document, but I can not further manipulate it (rotate it, mirror it, add a caption etc).

A useful tip when trying to decide what width is appropriate for the particular image is to take advantage of the silently defined parameter \textwidth. LaTeX lets you use a multiplication factor to set legths required in objects, such as texwidth, margins etc. A simple way to that is:

\includegraphics[width=0.8\textwidth]{uoa_logo}   ← 80% of the textwidth
or
\includegraphics[width=0.4\textwidth]{uoa_logo}   ← 40% of the textwidth

This option is particularly useful when you have a document and for some reason you change its style (your publisher requires e.g. B5 paper instead). You stop depending on particular dimensions of the page you have defined and you present your image according to the document itself. Truly unique!

There are several other options for figure manipulation: borders, trimming, clipping, rotating and many more. See the links for more resources.

Our last example will give a general way to include figures in your thesis:

\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{uoa_logo}
\caption{A picture of the Univ. of Athens logo}
\label{fig:uoa_logo}
\end{figure}

In the above rather general example, we have also included a caption to be placed under the image (\caption{...} follows \includegraphics{...}) and a label so that we could refer to this image in the text with any further effort. The way to do that is the same with tables: at the point you would like to have a reference add the following command (given here in an example text paragraph)

[...] the head of Athena depicted in Fig.~\ref{fig:uoa_logo} was carved on a ring found during a recent archaeological mission [...] more data about the mission are included in table~\ref{tab:uoa_logo_data} [...]

On last tip: I use the character ~, which represents a blank space for LaTeX between Fig. and \ref{...} for two reasons. First, the obvious one is that I need a space inbetween. The second reason is that LaTeX considers this combo Fig.~\ref{fig:uoa_logo} as one word and will keep it together during hyphenation. This is similar to the \mbox{...} command that keeps its arguments together.