I'm trying to format the following table:
\documentclass[12pt]{report}
\usepackage[left=35mm, right=25mm, top=30mm, bottom=30mm]{geometry}
\usepackage{tabularx}
\usepackage[flushleft]{threeparttable} % package for tablenotes
\usepackage{booktabs,makecell,tabularx} % booktabs is used for horizontal lines (\toprule, \midrule, and \bottomrule)
\usepackage{array} % used together with tabularx
\usepackage{mathcomp} % for symbols
\begin{document}
\begin{table}[htbp]
\begin{threeparttable}
\caption{\linespread{1}\selectfont Fetal and neonatal complications in type 1 diabetic pregnancies and the general obstetric population}
\footnotesize
\linespread{1}\selectfont
\begin{tabularx}{\textwidth}{lcXXX}
& \multicolumn{2}{X}{Proportions (\% if not indicated otherwise)} & \multicolumn{2}{X}{OR (95\% Cl) for group differences} \tabularnewline
\cline{2-5}
Outcome variable & Type 1 diabetes & Control & Crude & Adjusted \tabularnewline
\toprule
Stillbirth & 1.5 & 0.3 & 4.04 (3.02--5.40)) & 3.34 (2.46--4.55)\tabularnewline
Fetal distress & 14 & 12.3 & g & h\tabularnewline
Perinatal mortality (\textperthousand) & 20 & j & k & l\tabularnewline
Neonatal mortality, 0--7 days (\textperthousand) & 5.1 & n & o & p\tabularnewline
Neonatal mortality, 0--28 days (\textperthousand) & 7.0 & 0.3 & 4.04 (3.02--5.40)) & 3.34 (2.46--4.55)\tabularnewline
Birth \textless37 weeks gestational age & 21 & 0.3 & 4.04 (3.02--5.40)) & 3.34 (2.46--4.55)\tabularnewline
Birth \textless37 weeks gestational age & 2.3 & 0.3 & 4.04 (3.02--5.40)) & 3.34 (2.46--4.55)\tabularnewline
LGA & 31 & 0.3 & 4.04 (3.02--5.40)) & 3.34 (2.46--4.55)\tabularnewline
SGA & 2.3 & 0.3 & 4.04 (3.02--5.40)) & 3.34 (2.46--4.55)\tabularnewline
Major malformations & 4.7 & 0.3 & 4.04 (3.02--5.40)) & 3.34 (2.46--4.55)\tabularnewline
Apgar score \textless7 at 5 min & 3.1 & 0.3 & 4.04 (3.02--5.40)) & 3.34 (2.46--4.55)\tabularnewline
Apgar score \textless4 at 5 min & 0.80 & 0.3 & 4.04 (3.02--5.40)) & 3.34 (2.46--4.55)\tabularnewline
Erb palsy* & 2.1 & 0.3 & 4.04 (3.02--5.40)) & 3.34 (2.46--4.55)\tabularnewline
Respiratory distress syndrome & 1.0 & 0.3 & 4.04 (3.02--5.40)) & 3.34 (2.46--4.55)\tabularnewline
Respiratory disorders & 9.5 & 0.3 & 4.04 (3.02--5.40)) & 3.34 (2.46--4.55)\tabularnewline
\bottomrule
\end{tabularx}
\label{tab:fetal}
\begin{tablenotes}
\footnotesize
\item{\linespread{1}\selectfont Data are proportions or OR (95\% Cl). Adjusted OR, OR adjusted for group differences in maternal age, BMI, parity, chronic hypertensive disorder, smoking habits, and ethnicity. *Vaginal deliveries only.}
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
However, this is the output:
And this is what I would like to get:
Do you know how to properly format this table?
Best Answer
You need to
increase the widths of the 2-column headers
adjust the relative widths of the
X
-type columns so that no line wrapping is required in the final two columns. In the code below, observe that the relative widths of the fourL
columns sums to4
(the number of such columns), and that the relative widths of the twoC
columns also sums to4
.Addendum to address the OP's follow-up question: I assume the additional objective of aligning numbers on their (implicit or explicit) decimal markers pertains to columns 2 and 3 of the table. As the following table shows, it's possible to use the
S
column type for the numbers and to use (modified)C
columns for the two headers cells -- "Type 1 diabetes" and "Control", respectively. Note, incidentally, that the cell entries "j" and "n" need to be encased in curly braces to keep siunitx from (mis)interpreting what these symbols may mean.