Search

Tech Tip's : Do's and dont's

Month

May 2015

Website Collections for Students

Advertisements

Table Formatting in Latex for Academic Paper

Table Formatting in Latex for Academic Paper

Tables

Special Thanks to Andy Roberts for writing this article In academic writing, tables are a common feature, often for summarising results from research. It is therefore a skill that needs mastering in order to produce good quality papers.
However, if there is one area about Latex that I feel is the least intuitive, then I am afraid that this is it. Basic tables are not too taxing, but you will quickly notice that anything more advanced can take a fair bit of construction. So, we will start slowly and build up from there.

The Tabular environment

To begin, we shall first get familiar with some Latex terminology. An environment in Latex is a special declaration for formatting specific types of text. For example, in the bibliographies tutorial the abstract environment was introduced, so that the abstract of the paper could be formatted differently that the main body of text. All environments begin and end in the same fashion:

\begin{environment-name}
...
...
\end{environment-name}

The tabular is another such environment, designed for formatting your data into nicely arranged tables. Arguments are required after the environment declaration to describe the alignment of each column. The number of columns does not need to be specified as it is inferred by looking at the number of arguments provided. It is also possible to add vertical lines between the columns here. The following symbols are available to describe the table columns:

l left-justified column
c centered column
r right-justified column
| vertical line
|| double vertical line

Once in the environment,

& column separator
\\ start new row
\hline horizontal line

Note, any white space inserted between these commands is purely down to ones’ preferences. I personally add spaces between to make it easier to read.
There also exists a handy array package which extends some of the features of the tabular environment. In particular, there are three additional column formatting arguments:

p{width} paragraph column with text vertically aligned at the top
m{width} paragraph column with text vertically aligned in the middle
b{width} paragraph column with text vertically aligned at the bottom

Obviously, you must remember to \usepackage{array} in your document preamble.

Very basic table

This example shows how to create a simple table in LaTeX. It is a three-by-three table, but without any lines.

\begin{tabular}{ l c r }
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{tabular}
basic 3 by 3 table with values 1 to 9

Expanding upon that by including some vertical lines:

\begin{tabular}{ l | c || r | }
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{tabular}
basic table with   vertical lines

To add horizontal lines to the very top and bottom edges of the table:

\begin{tabular}{ l | c || r | }
\hline
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\hline
\end{tabular}
basic table with   vertical lines and horizontal lines at the top and bottom.

And finally, to add lines between all rows, as well as centring (notice the use of the center environment – of course, the result of this is not obvious from the preview on this web page, so look at the PDF output):

\begin{center}
\begin{tabular}{ l | c || r | }
\hline
1 & 2 & 3 \\ \hline
4 & 5 & 6 \\ \hline
7 & 8 & 9 \\
\hline
\end{tabular}
\end{center}
basic table with   horizontal lines at top, bottom and between each row; vertical lines between 1st and 2nd columns, and right edge; double-vertical lines between 2nd and 3rd columns

Text wrapping in tables

LaTeX’s algorithms for formatting tables have a few shortcomings. One is that it will not automatically wrap text in cells, even if it has overrun the width of the page. For columns that you know will contain a certain amount of text, then it is recommended that you use the p attribute and specify the desired width of the column (although it may take some trail-and-error to get the result you want).
Before we can proceed, we must introduce the Latex system of using measurements. This is quite flexible, as you can choose from a variety of length units.

  • pt – a point is 1/72 inch.
  • mm – millimetre.
  • cm – centimetre.
  • in – inch.
  • ex – roughly the height of an ‘x’ in the current font.
  • em – roughly the width of an ‘M’ (note the uppercase) of the current font.

There are also things known as command lengths, which are not fixed values as they depend on the configuration of the current document class and/or preamble. Useful ones include:

  • \parindent – the size of the paragraph indent
  • \baselineskip – vertical distance between lines.
  • \parskip – the extra space between paragraphs.
  • \textwidth – the width of a line of text in the local environment (e.g., the lines are commonly narrower in the abstract than in the normal text).
  • \textheight – the height of the text on the page.

The examples prepared are quite long because I was illustrating what happens when there is a fair bit of text in table cells. So instead of reproducing it within the page, go directly to the example LaTeX file, wrapped.tex and then view the output.

The Tabular* environment – controlling table width

This is basically a slight extension on the original tabular version, although it requires an extra argument (before the column descriptions) to specify the preferred width of the table.

\begin{tabular*}{0.75\textwidth}{ | c | c | c | r | }
\hline
label 1 & label 2 & label 3 & label 4 \\
\hline
item 1 & item 2 & item 3 & item 4 \\
\hline
\end{tabular*}

However, that doesn’t look quite as intended. The columns are still at their natural width (just wide enough to fit their contents whilst the rows are as wide as the table width specified. This looks very ugly. The reason for the mess is that you must also explicitly insert extra column space. Fortunately, Latex has rubber lengths, which unlike others, are not fixed, and Latex can dynamically decide how long they should be. So, the solution the current problem is:

\begin{tabular*}{0.75\textwidth}{@{\extracolsep{\fill}} | c | c | c | r | }
\hline
label 1 & label 2 & label 3 & label 4 \\
\hline
item 1 & item 2 & item 3 & item 4 \\
\hline
\end{tabular*}

You will notice the @{…} construct added at the beginning of the column description. More details of this will be coming shortly. Within it is the \extracolsep command, which requires a width. A fixed width could have been used, however, by using a rubber length, such as \fill, the columns are automatically spaced evenly.

@-expressions

It is probably worth addressing the @ specifier now that it has been introduced, even though there aren’t very many obvious applications for it.
It typically takes some text as its argument, and when appended to a column, it will automatically insert that text into each cell in that column before the actual data for that cell. It is worth noting that once used, inter-column space between the affected columns is suppressed. To add space, use @{\hspace{width}}.
Admittedly, this is not that clear, and so will require a few examples to clarify. Sometimes, it is desirable in scientific tables to have the numbers aligned on the decimal point. This can be achieved by doing the following:

\begin{tabular}{r@{.}l}
3&14159\\
16&2\\
123&456\\
\end{tabular}
using tables to align numbers on the decimal point

Its space suppressing qualities actually make it quite useful for manipulating the horizontal spacing between columns. Given a basic table, and varying the column descriptions:

\begin{tabular}{|l|l|}
\hline
stuff & stuff \\ \hline
stuff & stuff \\
\hline
\end{tabular}
{|l|l|} normal 2 by 2 table
{|@{}l|l@{}|} Using specifiers to    remove left cell padding on the first column; remove right cell padding on the second column.
{|@{}l@{}|l@{}|} using specifiers to    removed left and right cell padding for first column; remove right cell padding on the second column
{|@{}l@{}|@{}l@{}|} using specifiers to    remove left and right cell padding for both columns

Spanning

To complete this tutorial, a quick at how to generate slightly more complex tables. Unsurprisingly, the commands necessary have to be embedded within the table data itself.

Rows spanning multiple columns

The the command for this looks like this: \multicolumn{num_cols}{alignment}{contents}. num_cols is the number of subsequent columns to merge; alignment is pretty obvious, either l, c, or r. And contents is simply the actual data you want to be contained within that cell. A simple example:

\begin{tabular}{|l|l|}
\hline
\multicolumn{2}{|c|}{Team sheet} \\
\hline
GK & Paul Robinson \\
LB & Lucus Radebe \\
DC & Michael Duberry \\
DC & Dominic Matteo \\
RB & Didier Domi \\
MC & David Batty \\
MC & Eirik Bakke \\
MC & Jody Morris \\
FW & Jamie McMaster \\
ST & Alan Smith \\
ST & Mark Viduka \\
\hline
\end{tabular}
Using multicolumn for    making cells that span columns; header row spans both columns

Columns spanning multiple rows

The first thing you need to do is add \usepackage{multirow} to the preamble. This then provides the command needed for spanning rows: \multirow{num_rows}{width}{contents}. The arguments are pretty simple to deduce. With the width parameter, you can specify a fixed with if you wish, or, if you want the natural width (i.e., just wide enough to fit the contents of the column) then simply input an asterisk (*). This approach was used for the following example:

\begin{tabular}{|l|l|l|}
\hline
\multicolumn{3}{|c|}{Team sheet} \\
\hline
Goalkeeper & GK & Paul Robinson \\ \hline
\multirow{4}{*}{Defenders} & LB & Lucus Radebe \\
& DC & Michael Duberry \\
& DC & Dominic Matteo \\
& RB & Didier Domi \\ \hline
\multirow{3}{*}{Midfielders} & MC & David Batty \\
& MC & Eirik Bakke \\
& MC & Jody Morris \\ \hline
Forward & FW & Jamie McMaster \\ \hline
\multirow{2}{*}{Strikers} & ST & Alan Smith \\
& ST & Mark Viduka \\
\hline
\end{tabular}

Demonstrating the multirow package: a table where some cells have heights greater than one row

The main thing to note when using \multirow is that for the subsequent rows that are to be spanned, a blank entry for the appropriate cells have to be inserted.

Summary

That’s about it for basic tables in my opinion. After you experiment, you do quickly get up to scratch. I must admit, the table syntax in Latex can look rather messy, and so seeing new examples can look confusing. But hopefully, enough has been covered here so that you can create any table you are likely to need for your papers. Unsurprisingly, Latex has plenty more up its sleeve, so expect a follow up tutorial covering more advanced features in the near future.

Latex Tips for publishing papers

LaTeX tips to meet publication page limits

Any print publication will naturally have a page limit for articles it publishes. I use LaTeX for typesetting my papers, and I’ve put together here a collection of tricks I use to squeeze space out. I’ve sorted them roughly in decreasing order of effectiveness.

Do this first

  • Decrease the document’s font size to the lowest allowed size. For example, \documentclass[10pt]{article} reduces your document’s font to 10 points if you’re using the article document class.
  • If you’re using the article document class, add \usepackage{fullpage} to your preamble. As its name suggests, this package shrinks the margins and uses more of each page.
  • Convert display math (equation, eqnarray, etc.) to inline math ($ $), wherever possible.

Decrease the font size used for references

It is common for print journals to use a smaller font for references than normal text. But the default style files for conference papers (like ACM‘s sig-alternate.cls) often don’t do this. You can do this yourself by enclosing the bibliography portion of your document with a LaTeX font size environment like this:

\small{
    \bibliography{mybibliographyfile.bib}
}

To make the references even smaller, use \scriptsize instead of \small, but I don’t recommend using smaller font sizes.

Reduce spacing by changing environment variables

LaTeX uses certain default values set by the style-sheet to determine, for example, the spacing between items in a list, before and after equations, before and after figures, etc. This document on Squeezing Space in LaTeX gives a list of such variables you can manipulate. They usually involve adding a negative amount of space to an existing environment variable. For example:
\addtolength{\itemsep}{-0.05in}
The above code reduces the separation between items in a list by 0.05 inches. The right amount to add can only be found by trial and error. I’ve found that it is most effective to change the following variables: \itemsep (about 0.1 in), \topsep(about 0.07 in), \textfloatsep(about 0.05 in), \intextsep(about 0.05 in), \partopsep(about 0.03 in), \parskip(about 0.02in)
Note that sometimes, adding a more negative amount does not seem to reduce spacing, and when pushed beyond a point, the typesetting gets totally messed up. Use this technique in moderation.

Using \vspace

This is a more direct method to cut down spacing exactly where you need it. It is best illustrated with an example:

This is the end of a paragraph.
\vspace{-0.2in}
\begin{figure}[h]

This cuts down the space between the end of a paragraph and the figure that follows it.

Use the space meant for author information

If you are submitting a paper for a double blind-reviewed conference, you will not be revealing the author names and affiliations. But the style file often reserves a certain amount of space for it, even if you don’t specify any author information. The only way around is to edit the style file itself. This is how you can do it for ACM’s sig-alternate.cls (Note: you make such modifications at your own risk, I have only tested this for v1.6 of the class file).

  • Find the line \advance\topmargin by -37 pt. Change the 37 to 47.
  • Find the line %This should be the subtitle. Comment the next six lines.
  • Find the line ending with % Increased space for title box -- KBT, and comment it.
  • Comment the line \newtoks\copyrightnotice.
  • Skip the next three lines. Comment the next six lines (\begin{center} to \end{center}).
  • Find the line starting with \def\@toappear{}. Comment this line, and the next six lines (up to and including the line that begins with \def\conferenceinfo.)
  • Find the line starting with \newtoks\copyrtyr. Comment this line, and the next seven lines (up to and including the line that begins with \def\permission.)

Fix paragraphs that end at the beginning of a column

In any document, it is common to have paragraphs where the last character is at the beginning of a column. Often, it is possible to shorten that paragraph just enough to make the paragraph end in the previous line instead, thus saving one entire line. Browse you entire document looking for such paragraphs, and fix as many as you can.

Convert oversized tables into images

Sometimes, we have tables that span more than one column, but does not really need two columns. For example, the following table may not fit into a single column.

\begin{table}
\centering
\begin{tabular}{l l l l l l l}
    BlahBlah & BlahBlah & BlahBlah & BlahBlah & BlahBlah & BlahBlah & BlahBlah\\
\end{tabular}
\caption{BlahBlah table}\end{table}

But, we can use the same trick we use for resizing images to make this table fit into, say 90% of the column width, like this:

\begin{table}
\centering
\resizebox{0.9\columnwidth}{!}{
    \begin{tabular}{l l l l l l l}
        BlahBlah & BlahBlah & BlahBlah & BlahBlah & BlahBlah & BlahBlah & BlahBlah\\
    \end{tabular}
}
\caption{BlahBlah table}
\end{table}

Shrink images

This obvious trick is, IMO, the main cause of illegible conference papers, but sometimes, there is no other choice. Shrink your images using your favorite LaTeX graphics package till the text size on the figure is about the same size as the main text.

Bibliography

For bibliography use
 
\bibliographystyle{unsrt}
\bibliography{Bib_Filename_without.bib_here}

Use \cite{reference_name} wherever you wish to cite the reference and compile in latex with bibtex enabled. The option for TexMaker is PdfLaTeX + Bib(la)tex + PdfLaTeX(x2) + View Pdf that one can find in the Options > Configure TeXMaker > Quick Build option

Create the .bib file that is present in the same folder as the parent tex file.

For the .bib file try to search for the paper in Google Scholar to get citations faster.
There is a Cite option in every paper result that Google Scholar displays. Use Bibtex in bottom of the Cite option pop that comes up. Copy this citation as it in the .bib file.Use comma as the separation for the paper citations in the bib file.
In case you dont find the desired paper on Google Scholar which is pretty rare 🙂
unless its IEEE papers that are not meant to be publicly available. Then go to the IEEE Xplore page and search for the paper. You will have the download citation option for the paper that is present on the webpage.
And there your file of .bib will be ready in minutes.

——————————————————————————————————————————-

Like the post. Leave comments.


Create a free website or blog at WordPress.com.

Up ↑