8

My text alignment of the column headers - "Cumulative Number of Courses Required to be Passed" and "Cumulative Number of Senior Courses Required to be Passed" are clearly wrong. I do recognise that these are unusually long column headers, but I can't think of a more precise term than that at the moment.

enter image description here

What I'd like is the two column headers to "wrap" more around the "BSc" and "EDP", although not exactly. Perhaps if the cut off is on the word "Courses" (move 'Required' to the second line), that would be nice. Also is it possible to move the EDP columns a bit more to the right, so that it is more closely aligned with the word "Courses" above?

MWE:

\documentclass{article}
\usepackage{booktabs, threeparttable}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}

\begin{document}
\begin{table}[H]
\begin{threeparttable}
\caption{Minimum Requirements for Automatic Readmission into the Science Faculty}
\label{table:sci}
\begin{tabular}{@{}p{0.18\textwidth}*{4}{L{\dimexpr0.1\textwidth-2\tabcolsep\relax}}@{}}
\toprule
& \multicolumn{2}{c}{\bfseries Cumulative Number of Courses Required to be Passed} &
\multicolumn{2}{c}{\bfseries Cumulative Number of Senior Courses Required to be Passed}  \\
\cmidrule(l){2-3} \cmidrule(l){4-5}
& BSc & EDP & BSc & EDP  \\
\midrule
First-year & 2 & 2 & --- & ---  \\
Second-year & 7 & 6 & --- & --- \\
Third-year & 11 & 10 & 3 & 2 \\
Fourth-year & 15 & 14 & 6 & 5 \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}
9

I made three changes to your table:

1) I added \centering

2) I changed the width of the 4 right-side columns to 0.2\textwidth..., and

3) I placed the headers each in its own \Longstack. This required three additional tweaks in the preamble: add the stackengine package; tell the package to use \# as the end-of-line, since tabular is already using \\ (note that the latest stackengine version 4.00 can use \\ end-of-line delimiters, even nested inside a tabular); and tell the package to set 12pt between baselines of the stack lines, since tabular zeroes out the value of \baselineskip, which is otherwise the default long-stack gap. Note that you can give the \Longstack a [l] or [r] optional argument to change it from the default [c] alignment.

\documentclass{article}
\usepackage{booktabs, threeparttable, stackengine}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\setstackEOL{\#}
\setstackgap{L}{12pt}
\begin{document}
\begin{table}[ht]
\centering
\begin{threeparttable}
\caption{Minimum Requirements for Automatic Readmission into the Science Faculty}
\label{table:sci}
\begin{tabular}{@{}p{0.18\textwidth}*{4}{L{\dimexpr0.20\textwidth-2\tabcolsep\relax}}@{}}
\toprule
& \multicolumn{2}{c}{\bfseries \Longstack{Cumulative Number\# of Courses Required\# to be Passed}} &
\multicolumn{2}{c}{\bfseries \Longstack{Cumulative Number of\# Senior Courses Required\# to be Passed}}  \\
\cmidrule(l){2-3} \cmidrule(l){4-5}
& BSc & EDP & BSc & EDP  \\
\midrule
First-year & 2 & 2 & --- & ---  \\
Second-year & 7 & 6 & --- & --- \\
Third-year & 11 & 10 & 3 & 2 \\
Fourth-year & 15 & 14 & 6 & 5 \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}

enter image description here

  • I noticed that the gaps between "first-year", "second-year", third year etc, are wider, which I guess is what you meant by "tell the package to set 12pt between baselines of the stack lines". It looks very pleasant - is it possible to have that gap applied to other tables without using the long stack command? I would like to apply it to all my other tables. – The Statistician Magician Mar 18 '14 at 11:44
  • @Chris I don't believe the stacking gap affects anything other than the contents of the \Longstacks themselves. For example, take my MWE, and change the 12pt to 20 pt, and see what happens. I can't account for perceived changes elsewhere. – Steven B. Segletes Mar 18 '14 at 11:57
  • @Chris However, if you did wish to spread out the lines of the complete table, \renewcommand\arraystretch{1.1} right before the threeparttable would accomplish that. – Steven B. Segletes Mar 18 '14 at 11:59
5

Don't use c in \multicolumn{2}{c}{... but

 \multicolumn{2}{L{\dimexpr0.3\linewidth-8\tabcolsep\relax}}{...

Full code:

\documentclass{article}
\usepackage{booktabs, threeparttable}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}


\begin{document}
\begin{table}[H]
\begin{threeparttable}
\caption{Minimum Requirements for Automatic Readmission into the Science Faculty}
\label{table:sci}
\begin{tabular}{@{}p{0.18\textwidth}*{4}{L{\dimexpr0.3\linewidth-8\tabcolsep\relax}}@{}}
\toprule
& \multicolumn{2}{L{\dimexpr0.4\linewidth-4\tabcolsep\relax}}{\bfseries Cumulative Number of Courses Required to be Passed} &
\multicolumn{2}{L{\dimexpr0.4\linewidth-4\tabcolsep\relax}}{\bfseries Cumulative Number of Senior Courses Required to be Passed}  \\
\cmidrule(l){2-3} \cmidrule(l){4-5}
& BSc & EDP & BSc & EDP  \\
\midrule
First-year & 2 & 2 & --- & ---  \\
Second-year & 7 & 6 & --- & --- \\
Third-year & 11 & 10 & 3 & 2 \\
Fourth-year & 15 & 14 & 6 & 5 \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.