# How to Deal with Wide Tables

Ahhhh tables — one of the infuriating things with tables in LaTeX, is that sometimes they’re so wide that they extend into the right margin, or even off the page. Here are a few things I usually do to deal with them.

### The simplest: just make the whole table use a smaller font.

{\small % (or \footnotesize if still readable) \begin{tabular} ... \end{tabular} }

Do check that you have the pair of braces around the \small and the tabular. Take care that the table contents can still be read comfortably, and that your university or publisher allows you to change the font size in tables!

### Let LaTeX shrink the entire table to text width.

\resizebox{\textwidth}{!}{% \begin{tabular} ... \end{tabular} }

Rather than figuring out whether a \small or \footnote will be enough ourselves, LaTeX will treat the entire table as a box, and try to resize it so that it fits the text width exactly. Again: take care that your reader can still read the shrunk table, and that it’s allowed by your university or publisher.

### Use makecell to quickly break a cell into multiple lines

Sometimes you have a column with narrow values (e.g. just ‘34’, ‘67’…) but the column heading is long (e.g. ‘No. of patients’, which makes the column use up too much space. In this case you can use the makecell package, and then manually line-break the column heading:

\makecell{No. of\\patients} & Region & .... \\ % Note that All of the above are still on the same table row.

### Use tabularx to auto-wrap long column contents

Sometimes you have a column where the lines are long, but by default, lines in a table row don’t wrap. You can either use the makecell trick to manually break the lines; or you can make text in that particular column line-wrap automatically, by using a p{3cm} column specifier (but then you need to experiment a few times for a right width), or by using the tabularx package.

\usepackage{tabularx} ... % Contents in the second and third columns will be auto-wrapped, % so that the entire table will fit the text width nicely \begin{tabularx}{\textwidth}{l X X l} No. & These are long statements... & These are very long too... & 0\\ ... \end{tabularx}

### Make the table landscape

There are a few different ways of doing this — try for example the sidewaystable environment from the rotating package:

\usepackage{rotating} ... \begin{sidewaystable} \caption{...} \begin{tabular} ... \end{tabularx} \end{sidewaystable}

And always remember: rather than agonising over how to fit a table on the page, it’s often more useful to consider how to present the data so that the reader can access and understand it easily!

# 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.

 Student MidTerm Finals Total Ali 43 33 73.0 Abu 20 23 43.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}
\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.