Using Tables with LaTeX

Using tables with LaTeX is a little tricky. The good thing is, once you get the hang of it, it’s really very clean. Here’s a crash-tutorial on how to use tables.

We want to make this table:

Cat/Term apple recipe pudding
COOKING 1 0.37 0.37
SOCCER 0 0 0

And here’s the code to do it:

\begin{table}
    \centering
    \begin{tabular}{|l|c|c|c|}
        \hline
        Cat/Term & apple  & recipe    & pudding \ \hline
        COOKING  & 1      & 0.37      & 0.37    \ \hline
        SOCCER   & 0      & 0         & 0       \ \hline
    \end{tabular}
    \caption{Example representation of a user profile}
    \label{fig:sampleM}
\end{table}

Most of this is self-explanatory if you know a little LaTeX. I’ll give a short guide on the rest. (Feel free to ask if you have any problems.)

The { l c c c } means that there should be four columns: first one left aligned and the rest centered. Between each column, there should be a line. Try removing one of these pipes to see the difference.

The first \hline is used to insert a line at the top of the table.

Then, each line represents a row with the ampersands marking the column separations.

Each \hline at the end of rows means there should be a line between the rows. Try removing one of these to see what it does.

Of course, the \ means line break; or in this case, row break.

Hope this helps.