'Merging Rows and Columns for a Table
I have to create this table in LaTeX but I don't like the current way it looks right now. Here is what I want it to look like when I compile the code,

And this is the current code that I have along with the LaTeX output
\begin{tabular}{|c|c|c|c|c|}
\hline
& & \multicolumn{3}{c|}{\textbf{Mother}}\\
\hline
& & $u_n$ & $v_n$ & $0.5w_n$\\
\hline
& $u_n$ & $u_n^2$ & $u_nv_n$ & $0.5u_nw_n$\\
\hline
\textbf{Father} & $v_n$ & $u_nv_n$ & $v_n^2$ & $0.5v_nw_n$\\
\hline
& $0.5w_n$ & $0.5u_nw_n$ & $0.5v_nw_n$ & $0.25w_n^2$\\
\hline
\end{tabular}

Solution 1:[1]
You can get this table, even without nesting the two environments multicolumn and multirow (to use this latter, you need the package with the same name):
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|c|c|c|c|c|}
\hline
\multicolumn{2}{|c|}{} & \multicolumn{3}{c|}{\textbf{Mother}}\\
\cline{3-5}
\multicolumn{2}{|c|}{} & $u_n$ & $v_n$ & $0.5w_n$\\
\hline
\multirow{3}{*}{\textbf{Father}} & $u_n$ & $u_n^2$ & $u_nv_n$ & $0.5u_nw_n$\\
\cline{2-5}
& $v_n$ & $u_nv_n$ & $v_n^2$ & $0.5v_nw_n$\\
\cline{2-5}
& $0.5w_n$ & $0.5u_nw_n$ & $0.5v_nw_n$ & $0.25w_n^2$\\
\hline
\end{tabular}
\end{document}
Solution 2:[2]
The tabularray packages makes such layouts really easy:
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{
hlines,
vlines,
colspec={ccccc},
cells={mode=math},
cell{1}{3}={mode=text,font=\bfseries},
cell{3}{1}={mode=text,font=\bfseries}
}
\SetCell[c=2,r=2]{} & & \SetCell[c=3]{} Mother\\
& & u_n & v_n & 0.5w_n\\
\SetCell[r=3]{} Father & u_n & u_n^2 & u_nv_n & 0.5u_nw_n\\
& v_n & u_nv_n & v_n^2 & 0.5v_nw_n\\
& 0.5w_n & 0.5u_nw_n & 0.5v_nw_n & 0.25w_n^2\\
\end{tblr}
\end{document}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MattAllegro |
| Solution 2 |


