How to split a cell in a table in latex?
Asked Answered
P

2

5

I am wanting to create a table as a header in LaTeX. 3 columns, the first cell must span two rows, the second cell must span two rows and the third cell must be split between the two rows. So 4 cells total but 3 columns like the picture below. Im having trouble with the spacing when I try and split the last column into two rows.

Table picture

Poesy answered 15/7, 2020 at 12:52 Comment(0)
O
6

One first sketch:

\documentclass{article}
\usepackage{multirow}

\begin{document}

\begin{tabular}{|c|c|c|}
\hline
\multirow{2}{*}{Some text A} & \multirow{2}{*}{Some text B} & Some text C\\
\cline{3-3}
 & & Some text D\\
\hline
\end{tabular}

\end{document}

This gives you:

screenshot of table

It is not clear to me if you want your middle column to be larger than the two on the sides. Anyway, see this other answer of mine!

Orran answered 15/7, 2020 at 21:13 Comment(2)
Many thanks. When using \centering for text C and D it shifts the clone to the first cell. Is there a fix for this?Poesy
@DuncanWilliamGibbons text C and text D are centered by default (check it with a longer text)...and I think \centering within one cell is not the wayOrran
K
1

The tabularray package makes merging cells very easy:

\documentclass{article}

\usepackage{tabularray}

\begin{document}

\noindent%
\begin{tblr}{
  colspec={lXc},
  vlines,
  hlines
}
\SetCell[r=2]{} some text & \SetCell[r=2]{} some long text some long text some long text & short text\\
&& short text\\
\end{tblr}

\end{document}
Keddah answered 24/11, 2022 at 9:27 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.