带方框的图表

带方框的图表

我需要制作一些类似这里给出的图表。但是,我需要每个图表中都有大小相等的适当方块,而不管方块内有多少文本。请提供任何指导。

\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}

答案1

使用tabularray(正如@projetmbc 在其评论中所建议的)包:

\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{tabularray}

\usepackage{lipsum}

\begin{document}
\lipsum[1]

    \begin{center}
\begin{tblr}{hline{2,3}, vline{1-Z} ={2-Z}{solid},
             colspec = {*{9}{Q[c, m, wd=2ex, mode=math]}},
            row{2-Z} = {ht=4ex},
             }
a   & b     & c     & d     & e     & f     & g     & h     & i     \\
S   & C_1   & C_2   & C_3   & C_4   & C_5   & C_6   & C_7   & C_8   \\
\end{tblr}
    \end{center}
\lipsum[2]

    \begin{center}
\begin{tblr}{hline{2-Z}={1-Y}{solid}, vline{1-Y}={2-Z}{solid},
             colspec = {*{10}{Q[c, m, wd=4ex, mode=math]}},
              colsep = 2pt,
                row{2-Z} = {ht=4ex},
            }
a   & b     & c     & d     & e     & f     & g     & h     & i     &       \\ 
S   & 1     & 2     & 3     & 4     & 5     & 6     & 7     & 8     & 36    \\ 
1   & S     & 1     & 2     & 3     & 4     & 5     & 6     & 7     & 29    \\ 
2   & 1     &S      & 1     & 2     & 3     & 4     & 5     & 6     & 24    \\
3   & 2     & 1     & S     & 1     & 2     & 3     & 4     & 5     & 21    \\ 
4   & 3     & 2     & 1     & S     & 1     & 2     & 3     & 4     & 20    \\
\end{tblr}
    \end{center}
\lipsum[3]

    \begin{center}
\begin{tblr}{hline{2-Z}={2-Z}{solid}, vline{2-Z}={2-Z}{solid},
             colspec = {*{9}{Q[c, m, wd=4ex, mode=math]}},
            row{2-Z} = {ht=4ex},
            }
    & a & b         & c         \\
1   & S & 1         & 2         \\ 
2   & S & 1         & 2\sqrt{2} \\ 
3   & S & 2\sqrt{2} & 2         \\  
\end{tblr}
    \end{center}
\end{document}

在此处输入图片描述

相关内容