I need to make some diagrams like those given here. However, I need boxes as proper squares of equal size in each diagram, irrespective of a few or more text inside the box. Any guidance, please.
\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{nccmath, amsmath}
\usepackage{lipsum}
\usepackage{array}
\begin{document}
\lipsum[1]
\newcommand\mc[1]{\multicolumn{1}{l}{#1}}
\centering
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
\mc{a} & \mc{b} & \mc{c} & \mc{d} & \mc{e} & \mc{f} & \mc{g} & \mc{h} & \mc{i} \\ \cline{1-9}
\it{S} & $C_1$ & $C_2$ & $C_3$ & $C_4$ & $C_5$ & $C_6$ & $C_7$ & $C_8$ \\ \cline{1-9}\end{tabular}
\lipsum[2]
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c}
\mc{a} & \mc{b} & \mc{c} & \mc{d} & \mc{e} & \mc{f} & \mc{g} & \mc{h} & \mc{i} & \mc{} \\ \cline{1-9}
\it{S} & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 36 \\ \cline{1-9}
1 & \it{S} & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 29 \\ \cline{1-9}
2 & 1 & \it{S} & 1 & 2 & 3 & 4 & 5 & 6 & 24 \\ \cline{1-9}
3 & 2 & 1 & \it{S} & 1 & 2 & 3 & 4 & 5 & 21 \\ \cline{1-9}
4 & 3 & 2 & 1 & \it{S} & 1 & 2 & 3 & 4 & 20 \\ \cline{1-9}
\end{tabular}
\lipsum[3]
\begin{tabular}{c|c|c|c|}
\mc{} & \mc{a} & \mc{b} & \mc{c} \\ \cline{2-4}
1 & \it{S} & 1 & 2 \\ \cline{2-4}
2 & \it{S} & 1 & $2\sqrt{2}$ \\ \cline{2-4}
3 & \it{S} & $2\sqrt{2}$ & 2 \\ \cline{2-4}
\end{tabular}
\end{document}
nicematrix
ortabularray
.