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.

Reduce the column paddings

So in some situations you can get away with making the inter-column separation or padding smaller:

\begin{table}[hbt!]
\setlength{\tabcolsep}{4pt} %% default is 6pt
\begin{tabular}....

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{tabular}
\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!

UMalayaThesis updated to v1.2 for Guidelines (2015)

Sigh, so I finally realised and managed to find the 2015 version of the UM thesis guidelines!!!

So I’ve updated the .cls and .tex (changes to existing v1.1.2), which includes the following updates:

  • Added a \faculty field
  • \makecoverandtitlepage now takes an option to output the
    relevant statement on the title page
  • Chapter headings are now single line, with less spacing after
    the chapter title.
  • Bibliography entries are now explicitly 0.5 inch indented and
    with really wide double spacing between entries.
  • Re-ordered elements in thesis.tex to match the updated guide.

You can download umalaythesis v1.2 from here, or from Bitbucket and Github, or open it as a an online project on Overleaf.

Paragraph indents and spacing

By default, LaTeX does not indent the first paragraph after a section command, but will indent all subsequent paragraphs.

You can, of course, add \indent to the start of each first paragraph. But that gets rather tedious after a while, and you might miss it if e.g. some time later, you add another paragraph immediately after the sectioning command.

Fortunately, the indentfirst package will do this automatically for you — rejoice!

If you need to change the indent amount (for all paragraphs), you can set the \parindent length:

\setlength{\parindent}{2em}

The inevitable next question: “What if I need to have some space between the paragraphs?”

Rule: Please don’t use \\\\ to achieve “space between paragraphs”. Please. Don’t.

\\ is for line breaks. Paragraph breaks in LaTeX are done by either leaving a blank line in the source code, or by using \par. Line breaks and paragraph breaks are two very, very distinct concepts in typesetting, and are handled differently in LaTeX.

So the easiest way to achieve this is simply by writing \usepackage{parskip}. This avoids modifying the \parskip length directly, because \parskip has consequences for many other constructs, e.g. itemize and enumerate lists.

If you happen to be using one of the Koma-Script document classes, you may get a warning message when you try to load parskip. In that case, just pass parskip as a document class option, e.g. \documentclass[parskip]{scrbook}.

If memoir is the document class in use instead, you can write \nonzeroparskip or \abnormalparskip{\baselineskip}.

Just take note: it’s usually considered redundant to have both non-zero paragraph spacing and paragraph indents, so all paragraph indents are suppressed when parskip is loaded. Having said that, if you do need the paragraphs to be indented as well (university thesis requirements), use the \setlength{\parindent}{2em} to force this.

USMThesis Updated (Again)

Following the most recent feedback from the Main Campus, USMThesis has been updated to v1.6.3 today. The changes this time are in usmthesis.tex, where the List of Publications is moved after the appendices (so now Main Campus and Engineering Campus are on the same page now!) Pun unintended.

Looking at the ChangeLog, usmthesis v0.1 was Nov 2005 — so it’s been 10 years!! In fact if anyone wants to host a meetup/talk or something, ping me.

USMThesis Updated

USMThesis has been updated to v1.6.2, following feedback from IPS that the page numbering of appendices should be turned off in the table of contents.

If you already have the template (v1.6.1) from September 2015 and don’t want to re-download the template again now, just add these lines before \appendix in your thesis.tex:

\addtocontents{toc}{\protect\cftpagenumbersoff{part}}
\addtocontents{toc}{\protect\cftpagenumbersoff{chapter}}

Also, from recent feedback, it looks like Main Campus-IPS requires the List of Publications before the abstracts; while the Engineering Campus IPS requires the List of Publications after the appendices. So do check with IPS of your respective campuses before you print your entire thesis!

Another thing — when printing out the PDF, do remember to set paper size to A4, and Scaling to 100% or None in the Print dialog. Many PDF viewer applications would set it to 92% or Fit on page by default, and then the font sizes would come out too small and the page margins too wide!