Featured Post

We've moved to tex.my!

It’s been great writing on Blogger.com, but we’ve decided to move to a new platform, thanks to some valuable help from a great, great friend...

Thursday, October 8, 2009

Tables in LaTeX (crash course)

When you start to use Latex seriously to write your paper, thesis, documentation, book or what not. You will eventually find the need to display tables for various reason. Presentation of your tables is somewhat important, to convey the right ideas and to help people understand what you are trying to tell them.

However, displaying tables in LaTeX can be a little bit of a challenge. But, when you get a hang of it. It should be relatively easy and you can display nice and clean tables. Here is a short tutorial for you to get started.

Suppose for the sake of example, you want to display a table below in LaTeX.

StudentMidTermFinalsTotal
Ali433373.0
Abu202343.0

And here’s is how your tex code should look like.

\begin{table}
\centering
\begin{tabular}{|l|c|c|r|}
\hline
Student & Midterm & Finals & Total \\ \hline
Ali & 43 & 33 & 73.0 \\ \hline
Abu & 20 & 23 & 43.0 \\ \hline
\end{tabular}
\caption{Example for student grades.}
\label{fig:sampleStud}
\end{table}

For most part of the code above, the LaTeX code is self-explanatory. But I'll give you a short guide anyways.

The {|l|c|c|r|} means that there are four columns. The first column is left aligned, the second and third column is centered and the fourth column is right aligned. Between each of the columns, there should be a line. This is represented by the pipe character. Try removing one of the pipes and see how it will affect your table. Experimenting with the code above is the first few ways for you to start making good looking tables on your own.

Now, about \hline. As you might guess, the \hline stands for horizontal line. The first \hline is used to insert a line at the top of the table. Each line represents a row. The \hline after that represent the next few horizontal lines in each row. Try removing one of the \hline and see how it will affect your table.

The ampersands marking "&" is to show separations of the column. You can really mess up the tables by getting rid of the ambersand sign.

Finally, the \\ means line break; or in this case, row break. You have to do this for each row to indicate that you are done with one row, and ready to work on the other.

Hope this helps.

No comments:

Post a Comment