Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

2 Answers 2

up vote 4 down vote accepted

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 \\; 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}[H]
\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

share|improve this answer
    
Thanks, this is great! –  Chris Mar 18 at 11:33
    
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. –  Chris Mar 18 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 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 at 11:59

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

share|improve this answer
    
Excellent. Thank you for the parsimonious solution @Harish Kumar –  Chris Mar 18 at 11:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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