LaTeX Tables Primer

I held off on posting this so that I didn’t have too many LaTeX posts in quick succession. Grab an effective LaTeX template, or learn why you should start using LaTeX.

So you’ve started using LaTeX, but you’re stuck trying to put your data into a table. Tables in LaTeX are THE most un-intuitive, poorly designed part of the otherwise slick and clean document prep software. When I first tried putting tables into docs, I did everything I could to avoid making tables. Eventually, importing snipped word/excell tables into LaTeX as images just wouldn’t cut it. I had to make a table.

So let’s get started. Open up a new LaTeX doc, I’m using my custom template that you can grab HERE. Get rid of the table of contents and the second section code. We’re going to begin by setting the bounding code that will tell our table how to look:

begin{table}[ht]
        begin{center}
                  begin{tabular}{| c | l | l |}

                  end{tabular}
        end{center}
caption{small{Look at this bitchin’ table!}}
label{table}
end{table}

After begin{tabular} there is a bracket with {| c | l | l |}. This code tell LaTeX how to justify text/images within columns and where to draw vertical lines separating columns. This gives you infinite freedom in how you want to design your table. You can make anything from this:

to this (using code {| c | l  r |}:

Why I’m keeping track of what my neighbor eats, aside, we have two very different tables from only a little change in code.

So now that we have our table style made, let’s input some data.

begin{table}[ht]

        begin{center}
                  begin{tabular}{| c | l | l |}
hline
                                      Bills & Amount & Paid?
                                     Rent & $475.00 & Yes
hline
                                     Electricity & $16.00 & Yes
hline
                                     Water and Gas & $30.00 & Yes
hline
        end{center}
caption{Look at this bitchin’ table!}
label{table}
end{table}

                  end{tabular}

Okay, let’s walk through the code. hline makes a horizontal line the width of your column. Column width is governed by th elength of text you have in a specific column, more on that later. Columns are separated from one another using the & command. The double backslash you see at the end of each line tells LaTeX to start a new row. We can separate rows nicely(and close off the bottom of our column) with another hline command.

So let’s talk about the problems with LaTeX tables. If we take a column with a lot of text in it, like…

begin{table}[ht]

        begin{center}
                  begin{tabular}{| c | l | l |}
hline
                                      Bills & Amount & Paid?
                                     Rent & $475.00 & Yes
hline
                                     Electricity & $16.00 & Yes 
hline
                                     Water and Gas & $30.00 & Yes
hline 

                                    Money I owe my neighbor for walking my dog while I was on vacation in Tahiti enjoying cheap beer and beautiful women while soaking in the sun and laughing at how my neighbor is cleaning up after my dog & $20.00  & No 

 hline
        end{center}
caption{Look at this bitchin’ table!}
label{table}
end{table}

                  end{tabular}

…will give us something like this:

Not bitching.

So how do we fix it? What we have to do is look at the pdf and make an educated guess at around what word we need to start a new row. Once we have that word, we type “& &” then to bring it to the next row.

The double “and” command tells the table that we’ve made it to the far side of the table, but we want those last columns to be blank.

The double backslash drops us to the next row.
So with this code:

begin{table}[ht]

        begin{center}
                  begin{tabular}{| c | l | l |}
hline
                                      Bills & Amount & Paid?
                                     Rent & $475.00 & Yes
hline
                                     Electricity & $16.00 & Yes 
hline
                                     Water and Gas & $30.00 & Yes
hline 

                                    Money I owe my neighbor for walking my dog while I was & &on vacation in Tahiti enjoying cheap beer and beautiful women& & while soaking in the sun and laughing at how my neighbor is& & cleaning up after my dog & $20.00  & No 

 hline
        end{center}
caption{Look at this bitchin’ table!}
label{table}

  end{tabular}

end{table}

                

 We get this:

bitching.
So use to divide up text and make your table the appropriate size. Don’t forget to add in & & for blank columns.
There ya have it, LaTeX tables are annoying to make, especially when you have a large amount of text for each column, but now at least you have a fighting chance of making it work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s