# Help with a booktabs table

I'm a relatively new user to Latex, and this is the first time I am attempting to construct a table for my thesis. I would like the table to look like this:

Following some research on the internet, I came up with the following code (ignore the differences in the column headings between the Latex code and the word document)

\begin{table}[htbp]
\caption{Minimum Requirements for Automatic Readmission into the Commerce Faculty}
\centering
\begin{tabular}{lrrrr}
\toprule
\multicolumn{2}{c}{{BCom} &
\multicolumn{2}{c}{B.Bus.Sci} \\
\cmidrule{2-3} \cmidrule{4-5} &
Number of courses required to pass & Cumulative Total of Courses && Number of courses &         Cumulative Total of Courses
\midrule
First year & 4 & 8 & 4 & 18 \\
\bottomrule
\end{tabular}
\label{table:mr}
\end{table}


it is not working at all!

• Without knowing the specifics of bookstable, you have a typo here: {{BCom}, and each row must end with \\ (missing in your "Number of courses ..." row). And the total of columns combined in multicolumns should equal your total number of columns of your table, so just put a & at the beginning of the row to produce an empty first colum. – Christof Mar 1 '14 at 13:27

A better version:

\documentclass{article}
\usepackage{booktabs}
\usepackage[margin=1in]{geometry}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\begin{document}
\begin{table}[htbp]
\caption{Minimum Requirements for Automatic Readmission into the Commerce Faculty}
\centering
\begin{tabular}{@{}p{0.12\textwidth}*{4}{L{\dimexpr0.22\textwidth-2\tabcolsep\relax}}@{}}
\toprule
& \multicolumn{2}{c}{BCom} &
\multicolumn{2}{c}{B.Bus.Sci} \\
\cmidrule(r{4pt}){2-3} \cmidrule(l){4-5}
& Number of courses required to pass & Cumulative Total of Courses & Number of courses &         Cumulative Total of Courses\\
\midrule
First year & 4 & 8 & 4 & 18 \\
\bottomrule
\end{tabular}
\label{table:mr}
\end{table}
\end{document}


1. You missed a & at the begining of

\multicolumn{2}{c}{{BCom} & \multicolumn{2}{c}{B.Bus.Sci} \\


making the first entry to go in to the first column.

2. You have a && in the line

Number of courses required to pass & Cumulative Total of Courses &&
Number of courses &         Cumulative Total of Courses


It should be & and you should put an & at the start of line. And at the end of this line you missed \\ just before \cmidrule.

Now the modifications

After correcting all the above, I have introduced a new column type with the help of array package.:

\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}


\raggedright is added to avoid ugly justification effects since the columns can be narrow and words can vary in length. This takes care of bad boxes also.

I have used this L column with a width

\dimexpr0.22\textwidth-2\tabcolsep\relax


through

*{4}{L{\dimexpr0.22\textwidth-2\tabcolsep\relax}}


As a side note, the \cmidrule can be shortened from left or right by

\cmidrule(r{4pt}){2-3}


Here {4pt} is the amount by which we shorten. It can be left off like \cmidrule(r){4-5}.

• Thanks very much. Works perfectly, and thanks for the thorough explanation. Just another quick question - the alignment of the heading of the table looks a bit silly -- my image. What are the options to make it look more aesthetically pleasing? Would it be possible to make the heading fit on one line? – The Statistician Magician Mar 1 '14 at 14:22
• @Chris I edited. Changes are in margin and the width of columns. This is the best possible with such long headers. :0 – user11232 Mar 1 '14 at 14:49
• @Chris As a side note, saying thanks here is best communicated by upvoting ( all the good answers) and accepting (the more useful answer). You may want to refer to How do you accept an answer? in case of doubts :) – user11232 Mar 1 '14 at 22:37
• hi @Harish Kumar, I have upvoted your answer and one other :). Just another quick question - how do I fill an empty cell in a table with a "-". I tried "\-" but the cell remains blank. – The Statistician Magician Mar 2 '14 at 7:03
• @Chris Thanks. :). You should put only -,(no \ ) or better $-$ or even better --- . Hope it helps. – user11232 Mar 2 '14 at 9:14

In addition to using the booktabs package (to get good-looking, i.e., well-spaced, horizontal lines), I would also recommend you use the tabularx package to simplify the job of getting four equal-width columns.

\documentclass{article}
\usepackage{booktabs,tabularx}
\usepackage[margin=1in]{geometry} % set margins to meet your document's needs
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
% use ragged-right, not fully-justified, look in narrow columns
\begin{document}
\begin{table}[t]
into the Commerce Faculty} \label{table:mr}
%\centering  % not needed, since table is as wide as text block
\begin{tabularx}{\textwidth}{@{}lYYYY@{}}
\toprule
&\multicolumn{2}{c}{\bfseries BCom}
&\multicolumn{2}{c}{\bfseries B.Bus Sci} \\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
&Number of courses required to pass
&Cumulative Total of Courses
& Number of courses
& Cumulative Total of Courses\\
\midrule
First year & 4 & 8 & 4 & 18 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}


Addendum: Incidentally, the look of the table you show in your posting can not be achieved when using the commands of the booktabs package. If you really need all those vertical and horizontal lines, you shouldn't use the command \toprule, \bottomrule, \midrule and \cmidrule. Instead, just use the basic-LaTeX \hline instruction. (You can, of course, still make use of the tabularx package to simplify the creation of equal-width columns for columns 2 to 5 of the table.)

These modifications will will lead to the table shown below. I hope you will agree that the "booktabs look" -- no vertical lines, fewer horizontal lines overall, and well-spaced rules -- is much preferable to what one might call the "spreadsheet look".

\documentclass{article}
\usepackage{tabularx}
\usepackage[margin=1in]{geometry}  % choose margin as needed
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
\begin{document}
\begin{table}[h!]
into the Commerce Faculty} \label{table:mr}
\begin{tabularx}{\textwidth}{|l|Y|Y|Y|Y|}
\hline
&\multicolumn{2}{c|}{\bfseries B. Com}
&\multicolumn{2}{c|}{\bfseries B. Bus. Sci} \\ \hline
& Number of courses required to pass
& Cumulative Total of Courses
& Number of courses required to pass
& Cumulative Total of Courses   \\ \hline
First  Year &  4 &  8 &  4 & 18 \\ \hline
Second Year & 10 & 16 & 11 & 16 \\ \hline
Third  Year & 18 & 24 & 20 & 25 \\ \hline
\end{tabularx}
\end{table}
\end{document}

• Hi - yes I do agree the booktabs look is far better. The image I had in my OP is from Word, and I was in a rush to post because I had to go off somewhere. The vertical lines were there because they come standard with the Word "table" tool. – The Statistician Magician Mar 1 '14 at 15:10

Have a look at the following:

\documentclass{scrartcl}
\usepackage{booktabs}
\begin{document}

\begin{table}[htbp]
\caption{Minimum Requirements for Automatic Readmission into the Commerce Faculty}
\centering
\begin{tabular}{p{0.2\textwidth}p{0.2\textwidth}p{0.2\textwidth}p{0.2\textwidth}p{0.2\textwidth}} \\ \toprule

& \multicolumn{2}{c}{BCom} & \multicolumn{2}{c}{B. Bus Scii} \\ \midrule
& Number of courses required to pass & Cumulative Total of Courses & Number of courses & Cumulative Total of Courses \\ \midrule
First year & 4 & 8 & 4 & 8 \\
Second year & 10 & 16 & 11 & 16 \\
Third year & 18 & 24 & 20 & 25 \\ \bottomrule
\end{tabular}
\end{table}

\begin{table}[htbp]
\caption{Minimum Requirements for Automatic Readmission into the Commerce Faculty}
\centering
\begin{tabular}{p{0.18\textwidth}p{0.18\textwidth}p{0.18\textwidth}p{0.18\textwidth}p{0.18\textwidth}} \\ \toprule

& \multicolumn{2}{c}{BCom} & \multicolumn{2}{c}{B. Bus Scii} \\ \midrule
& \multicolumn{1}{p{3.5cm}}{Number of courses required to pass} & Cumulative Total of Courses & \multicolumn{1}{p{2cm}}{Number of courses} & Cumulative Total of Courses \\ \midrule
First year & 4 & 8 & 4 & 8 \\
Second year & 10 & 16 & 11 & 16 \\
Third year & 18 & 24 & 20 & 25 \\ \bottomrule
\end{tabular}
\end{table}

\end{document}


You might try

\documentclass{amsart}
\usepackage{booktabs}
\begin{document}
\begin{table}[htbp]
\caption{Minimum Requirements for Automatic Readmission into the Commerce Faculty}
\centering
\begin{tabular}{@{}lp{3cm}p{3cm}p{3cm}p{3cm}@{}}
\toprule
&
\multicolumn{2}{c}{BCom} &
\multicolumn{2}{c}{B.Bus.Sci} \\
\cmidrule(r){2-3} \cmidrule(l){4-5}
\\
& Number of courses required to pass & Cumulative total of courses & Number of courses &         Cumulative total of courses
\\
\midrule
\\
First year & 4 & 8 & 4 & 18 \\
\bottomrule
\end{tabular}
\label{table:mr}
\end{table}

\begin{table}
\caption{Minimum Requirements for Automatic Readmission into the Commerce Faculty}
\centering
\begin{tabular}{@{}lrrr@{}}
\toprule
\\
\midrule
\\
BCom &
1 & 4 & 8 \\
& 2 & 4 & 8 \\
& 3 & 4 & 8 \\
B.Bus Sci &
1 & 4 & 18 \\
& 2 & 4 & 8 \\
& 3 & 4 & 8 \\
\bottomrule
\end{tabular}
\label{table:mr.2}
\end{table}
\end{document}