Merging cells in LaTeX tables is one of the most asked-about topics on r/LaTeX. The two commands you need are \\multicolumn (horizontal merge) and \\multirow (vertical merge).
Horizontal merge: \\multicolumn
Spans multiple columns into one cell:
\\begin{tabular}{lccc}
\\toprule
& \\multicolumn{3}{c}{Metrics} \\\\
\\cmidrule(lr){2-4}
Model & Precision & Recall & F1 \\\\
\\midrule
BERT & 0.89 & 0.85 & 0.87 \\\\
GPT & 0.91 & 0.88 & 0.90 \\\\
\\bottomrule
\\end{tabular}
Syntax: \\multicolumn{NUM_COLS}{ALIGNMENT}{CONTENT}
Vertical merge: \\multirow
Spans multiple rows. Requires \\usepackage{multirow}:
\\usepackage{multirow}
\\begin{tabular}{llcc}
\\toprule
Category & Model & Acc & F1 \\\\
\\midrule
\\multirow{2}{*}{Small} & DistilBERT & 0.82 & 0.80 \\\\
& TinyBERT & 0.79 & 0.77 \\\\
\\midrule
\\multirow{2}{*}{Large} & BERT-base & 0.89 & 0.87 \\\\
& RoBERTa & 0.91 & 0.90 \\\\
\\bottomrule
\\end{tabular}
Syntax: \\multirow{NUM_ROWS}{WIDTH}{CONTENT} — use * for auto width.
Combining both
You can nest \\multicolumn inside \\multirow for complex headers:
\\multicolumn{2}{c}{\\multirow{2}{*}{Combined Header}} \\\\
\\multicolumn{2}{c}{} \\\\ % empty row for the multirow span
Common mistakes
- Forgetting
\\cmidrule— use\\cmidrule(lr){2-4}instead of\\hlineunder merged headers - Wrong column count — merged cells still consume column slots; leave cells empty with
& - Missing package —
\\multirowrequires\\usepackage{multirow}
Skip the pain: Bibby's visual table builder handles merging with one click. Try Bibby AI free.