How to construct tables and diagrams

Tables are tricky to generate with LaTeX although with practice it becomes easier. The work involved pays dividends as there is a straightforward translation to HTML, thus avoiding lots of images cluttering our EAGLES web documents. Diagrams, graphs, etc., are best drawn in some graphics editor that allows you to generate an EPSF (Encapsulated PostScript File) which can then be incorporated rather straightforwardly in a LaTeX document.

Normally, you should enclose any table or diagram in a table or figure environment, respectively. Diagrams and tables enclosed in these environments float typically in LaTeX, such that they may not appear exactly where you thought they might: it all depends on how well LaTeX can re-arrange material to fit a figure in at some point. If you insert new material, your figure may float to some new position when you print your text. It is even possible to generate whole pages of nothing but tables and figures. If you do not allow tables and diagrams to float, this often causes rather messy output.

Tables are constructed by giving a specification for the number of columns needed and whether, for each colum, the text in it should be centred, leftjustified or rightjustified. You can also specify whether you wish the table to be boxed and/or to have dividing lines between the columns/rows.

In the following simple example, we specify 1 left justified column and 1 right justified column, with double lines down each side of the table, and single lines between columns and across the top and bottom. (NB: The justification used here is simply for exemplification. Normally, this table would have 2 leftjustified columns in all probability.) The command \hline will draw a horizontal line. The command \\ ends a row (which may take up more than one line in your file).

\begin{tabular}{||l|r||}\hline  

 Working Group	& Chairperson\\ \hline\hline

 SLWG 		& Roger Moore\\ \hline

 EWG 		& Maghi King\\ \hline

\end{tabular}

The specification {||l|r||} takes care of how many columns, which justification and what kind of vertical lines we want. Each row including the initial tabular row has a \hline command to generate a horizontal line (in the case of tabular the horizontal line is the first one generated to give the line across the top). The data in each row are separated by &. Note that if we use & for other purposes (e.g. E&AWG) we must place a backslash before it. Note that tabular & is a separator and not a terminator. Tabbing makes no difference: we have used tabs here just for clarity when reading the source file -- they are not strictly necessary. You should indicate an empty cell in a row by placing a tilde character in it.

Now we place the table in a table environment which will allow it to float to a reasonable position:

\begin{table}[!htb]

\vspace{1.5ex}

\centering

\begin{tabular}{||l|r||}\hline  

 Working Group	& Chairperson\\ \hline\hline

 SLWG 		& Roger Moore\\ \hline

 EWG	 	& Maghi King\\ \hline

\end{tabular}    

\caption{A table in a table environment\label{ls:tab}}    

\vspace{1.5ex}

\end{table}

The table is enclosed between \begin{table} and \end{table}. Usually, we put in a small amount of vertical space on each side of the table, using e.g. \vspace{1.5ex}, and we also centre the entire table (via \centering) and lastly attach a caption, which contains appropriate text. Please conform to this general layout, and please make sure captions are given.

The caption illustrates how a cross-reference should be done. LaTeX will automatically take care of cross-references: you should not attempt to do this yourself. The procedure is straightforward. At the appropriate point in your text, you insert a \ref command, and in the caption, you insert a \label command with the same reference. You can shift tables and figures around, and \ref indications in the text, and they will be kept track of. Here is the actual example, as it appears. Where it will appear is unknown as we type this, however we have tried to persuade LaTeX to put it where we specify it (immediately after this paragraph) by attaching the argument [!htb] to \begin{table}, which tells LaTeX to try putting the table where it is written in the file: h = here and if this would appear messy or is impossible, then to try other places, in order t = top of page or b = bottom of page. You can also force a table to be written on a page dedicated to tables: p = on a separate page of figures. This floating behaviour of tables makes a caption, and a cross-reference, indispensable. Please refer now to table 3.2. This last sentence was written:
Please refer now to table~\ref{ls:tab}.

 

Working Group Chairperson
SLWG Roger Moore
EWG Maghi King
Table 3.2: A table in a table environment 

By omitting the vertical bars and the \hline command, we can produce a table without any lines around it.

Note also that you do not need to use the table environment: you can just produce tabulars that do not float. Most of the tables in the EAGLES ELM series (cf. the documents of the EAGLES CLWG) were produced as simple tabulars, as otherwise the reports would have been illegible with so many tables floating with respect to often short stretches of text describing their contents.

It is also possible to produce multicolumn tables. Here is an example:

NOUNS
FeatureValues
POSn
Typecommonproper
Numbersing, pluralsing, plural
Genderm,fm,f

which was produced by:

\begin{center}

\begin{tabular}{|l||l|l|} \hline

\multicolumn{3}{|c|}{\bf NOUNS}\\ \hline\hline

{\bf Feature}&\multicolumn{2}{c|}{\bf Values}\\ \hline\hline

pos&\multicolumn{2}{c|}{n}\\ \hline

type&common&proper\\ \hline\hline

number&sing, plural&sing, plural\\

gender&m,f&m,f\\ \hline

\end{tabular}

\end{center}

Note that this neatly captures the hierarchical nature of the features and values to a useful extent.

As for diagrams, we recommend that these be produced externally to LaTeX and saved in EPSF form (Encapsulated PostScript File), unless you love drawing pictures in LaTeX. Most good packages that offer drawing facilities allow you to produce EPSFs. It is also best to deal with any need to orient your diagram or other figure before saving it as an EPSF. We can scale resultant figures within reason, but again it is better if you do this with your drawing package, as if you have e.g. a large figure with much small detail which we then scale down to fit on the page, you may find the small detail becomes illegible.

Here is an example of a floating figure that incorporates a simple tree diagram, scaled to a width of 15cm (scaling is proportional, we do not need to specify the height).

We attempt to place our diagram (figure 3.1 -- written: figure~\ref{ls:tree}) at the top of the page. The command \psfig takes care of reading in the external EPSF given as an argument. For this to work, you must make sure you have included the file initial.tex as it looks for and reads in the file psfig.sty which contains the relevant command. If psfig.sty is not in the same directory as this current file, then you should alter the relevant \usepackage command in initial.tex to give the relevant pathname of psfig.sty. You may have to also alter the pathname in the expression figure=filename if your EPSF is not in the current directory.

Here is our figure:

\begin{figure}[t]

\centering

\vspace{1.5ex}

% now give filename of an EPSF to include at this point

\psfig{figure=tree2.eps,width=15cm}

\vspace{1.5ex}

\caption{Generic-specific relationships\label{ls:tree}}

\end{figure}

The LaTeX code to produce the figure occurs in the source file roughly where this sentence is.

 figure415
Figure 3.1: Generic-specific relationships