# Alignment of multi-columns and line breaks within cells

I am failing to set up a complex APA table once again.

Actually, I need a table like shown below:

My current MWE:

\documentclass[12pt,ngerman]{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}

\begin{table}[!htb]
\begin{tabularx}{\textwidth}{Xcccccccccccc}  \toprule
& Dropout yes/no &  & & & & & & & & & \\
& No dropout & & & dropout & & & $MW_{dif}$ & $95\% CI for MW_{dif}$  & $t$ & $df$ & $d$ \\ \hline
& $MW$ & $SD$ & $N$ & $MW$ & $SD$ & $N$ & & & & & \\
General self-efficacy & $10$ & $2$ & $7$ & $29$ & $2$ & $7$ & $8$ & $23.50, 51.00$ & $2.12*$ & $12$ & $0.55$ \\
\bottomrule
\end{tabularx}
\end{table}

\end{document}


Problem 1: How do I align the upper part (Dropout yes/no) middle to both main areas no dropout and dropout? Vice versa, how do I align the second line to the MW-SD-N?

Problem 2: How do I achieve a line in the main areas which is just including MW/SD and N each?

• What is the specific problem you're having? Alignment of multi-columns? Line breaks within cells? Without an MWE, we have no way to target our answers. Additionally, the question, without MWE, is of the "do-this-for-me" type, which is not a good fit for the site. – Paul Gessler Jul 5 '14 at 15:04
• @PaulGessler, added the MWE due to your feedback. – Jens Jul 5 '14 at 15:43
• Your MWE has several things that are different from the desired output. It's always best to focus a question on a specific issue as this results in more helpful answers and increased usefulness to future visitors to the site. :-) – Paul Gessler Jul 5 '14 at 16:38
• Problem 1: use \multicolumn{<num_cols>}{<align>}{<content>} (basic example here, or search TeX.SE for many more). Problem 2: Use \cmidrule(<trim>){<start>-<end>} from the booktabs package. – Paul Gessler Jul 5 '14 at 16:57
• I will give it a try and upload the changed MWE – Jens Jul 5 '14 at 17:01

To centre (roughly) Dropout yes/no between No Dropout and Dropout, I insert a supplementary cell between their respective\multicolumn{3} and use a clap command. It would be perfectly centred if both strings had the same length, so I have to make a minor adjustment, adding some horizontal space.

I also use the makecell package, for line breaking in centred cells, and xcolor for decorative purpose:

\documentclass[10pt,a4paper, ngerman]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[x11names]{xcolor}
\usepackage{colortbl}
\usepackage{ragged2e}
\usepackage[margin = 2.5cm, nomarginpar]{geometry}
\usepackage{mathtools}
\usepackage{tabularx}
\usepackage{makecell}
\renewcommand\cellalign{cb}
\renewcommand{\tabularxcolumn}[1]{>{\RaggedRight\arraybackslash}m{#1}}
\usepackage{booktabs}

\begin{document}

\begin{table}[!htb]
\sffamily\setlength\tabcolsep{7pt}
\arrayrulecolor{Tomato3} \toprule\arrayrulecolor{DarkSlateGray4}
& & & & \clap{\hspace{0.8em}Dropout yes/no} \\
& \multicolumn{3}{c}{No dropout} & & \multicolumn{3}{c}{Dropout} & \\
\cmidrule(lr){2-4}\cmidrule(lr){6-8}
& MW & SD & N & & MW & SD & N & MW-Dif & \smash{\makecell{95\% CI\\ for MW-Dif}} & t & df & d\\
\cmidrule[\lightrulewidth](lr){1-13}
General self-efficacy & 10 & 2 & 7 & & 29 & 2 & 7 & 8 & 23.50, 51.00 & 2.12* & 12 & 0.55 \\
Vocational self-efficacy & 10 & 2 & 7 & & 29 & 2 & 7 & 8 & 23.50, 51.00 & 2.12* & 12 & 0.15 \\
Other scales & 10 & 2 & 7 & & 29 & 2 & 7 & 8 & 23.50, 51.00 & 2.12* & 12 & 0.11 \\
\arrayrulecolor{Tomato3} \bottomrule
\end{tabularx}
\end{table}

\end{document}


• Awesome minor improvements – Jens Sep 4 '14 at 0:17

This is my solution, based on the input from Paul Gessler in the comments:

\documentclass[12pt,ngerman]{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}

\begin{table}[!htb]
\begin{tabularx}{\textwidth}{Xcccccccccccc} \toprule
& \multicolumn{6}{c}{dropout yes/no} \\
& \multicolumn{3}{c}{no dropout} & \multicolumn{3}{c}{dropout} & & & &  \\
\cmidrule(rl){2-4} \cmidrule(rl){5-7}
& $\mathit{MW}$ & $\mathit{SD}$ & $\mathit{N}$ & $\mathit{MW}$ & $\mathit{SD}$ & $\mathit{N}$ & $\mathit{MW}_{\text{diff}}$ & $95\%$ KI für $\mathit{MW}_{\text{diff}}$ & $t$ & $df$ & $d$ \\  \midrule
General self-efficacy & $10$ & $2$ & $7$ & $29$ & $2$ & $7$ & $8$ & $23.50, 51.00$ & $2.12*$ & $12$ & $0.55$ \\

• Nice work! Now, a few more suggestions. :) 1) Multi-letter math variables (such as $MW$ or $SD$) should be set using $\mathit{MW}$ for better spacing. This will also make the table slightly narrower. 2) Since you're already using booktabs, you can replace \hline with \midrule. 3) Don't set text in math mode; switch back to text mode for proper spacing. Here's an example for your confidence interval cell: $95\%$ CI for $\mathit{MW}_{\text{diff}}$. Note: the \text{} macro is from the amsmath package and is useful for identifiers in math that are not variables. – Paul Gessler Jul 5 '14 at 18:14