Intro | First attempt | Text | References | Figures | Maths | Source Code | Theorems

Including figures and table

Figures

In order to include figures, I recommend the following sequence of commands.

  \begin{figure}
  \begin{center}
    \includegraphics[width=0.8\textwidth]{figfile}
  \end{center}
    \caption{A diagram showing how to include graphics.}
    \label{fig:1}
  \end{figure}

Additionally, in the preamble, you need:

  \usepackage{graphicx}

This does require a bit of explanation. First, a block enclosed by a \begin/\end pair is called an environment. The example uses two environments, figure and center.

figure environment
This creates a float, i.e. a block which is placed outside the flow of text, moved to give a good aesthetical result. Big chunks which cannot be split between pages should normally be placed in floats to allow the text to fill the pages.
center environment
This centres the enclosed material within the margins.
\includegraphics
This includes an external graphics file, figfile. You should usually omit the extension. pdflatex supports PNG and PDF, and sometimes JPEG. The optional argument says that the width should be 80% of the width of the text (i.e. between the margins. The height will be set to maintain the aspect ratio.
\caption
This specifies an explaining text to appear in the figure.
\label
This defines a key which can be used to refer to the figure later. E.g. See Figure~\ref{fig:1} on page~\pageref{fig:1}.

Table

The following code creates a table:

  \begin{table}
  \begin{center}
    \begin{tabular}{|r||c|l|}
      \hline
        Field 1 & Field 2 & Field 3 \\
      \hline\hline
        Data 1 & 0.5 & $\alpha$ \\
        Data 2 & 2.1 & $\beta$ \\
      \hline
    \end{tabular}
  \end{center}
    \caption{Table demo.}
    \label{tab:1}
  \end{table}

The table environment creates a float like figure does, but it keeps it in separate list with its own number sequence.

The actual table itself is made by the tabular environment.

{|r||c|l|}
This is the column specification. The pipes (|) represent vertical lines, and the letters represent fields, respectively right justified, centred and left justified.
\hline
makes a horizontal line.
&
separates fields.
\\
starts a new row

Lists of Figures/Tables

Whereever you want the lists, issue the commands

  \listoffigures
  \listoftables