# [Tex/LaTex] Wrapping text in a table cell

tables

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.

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}


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}