具有多列的表(层次表)

具有多列的表(层次表)

我正在尝试绘制如下图所示的表格层次表

我发现最接近我的查询的解决方案如下问题。我发现困难的是添加我提议的表格的最左边的列,即 $K_1$ 和 $K_2$ 的列。任何帮助都是值得赞赏的。

答案1

使用的解决方案tabularray

\documentclass[a4paper]{article}
\usepackage{tabularray}
\begin{document}
    \begin{tblr}{
        colspec={*{10}{X[c,m]}},
        width=\linewidth,
        cell{1}{2} = {r=2,c=1}{c},
        cell{1}{3,7} = {r=1,c=4}{c},
        cell{3,7}{1} = {r=4,c=1}{c},
        hline{2} = {3-Z}{solid},
        hline{1,3,7,Z} = {solid},
        hline{7} = {2}{-}{solid},
        vline{2,3,7} = {solid},
        vline{4-Y} = {2}{solid},
        vline{7} = {2}{-}{solid},
        hline{4-6} = {2-Z}{solid},
%       hline{8-10} = {2-Z}{solid}
        }
        & p & A & & & & B & & & \\
        &       & I & II & III & IV & I & II & III & IV \\
        $k_1$   & a &    &     &    &   &    &     &    \\
                & b &    &     &    &   &    &     &    \\
                & c &    &     &    &   &    &     &    \\
                & d &    &     &    &   &    &     &    \\
        $k_2$   & a &    &     &    &   &    &     &    \\
                & b &    &     &    &   &    &     &    \\
                & c &    &     &    &   &    &     &    \\
                & d &    &     &    &   &    &     &    \\
    \end{tblr}
\end{document}

输出

答案2

像这样吗?

在此处输入图片描述

\documentclass{article} % or some other suitable document class
\usepackage{tabularx,ragged2e,multirow}
\newcolumntype{C}{>{\Centering}X} % centered version of 'X' column type
\setlength\extrarowheight{2pt} % for a less cramped "look"
\begin{document}

\noindent
\begin{tabularx}{\textwidth}{ l | l | C | C | C | C || C | C | C | C }
\hline
  &   & \multicolumn{4}{c||}{A} & \multicolumn{4}{c}{B} \\
\cline{3-10}
  & p & I & II & III & IV & I & II & III & IV \\
\hline
\multirow{4}{*}{$K_1$} & 
    a & \multicolumn{4}{c||}{} \\ \cline{2-10}
  & b & \multicolumn{4}{c||}{} \\ \cline{2-10}
  & c & \multicolumn{4}{c||}{} \\ \cline{2-10}
  & d & \multicolumn{4}{c||}{} \\
\hline\hline
\multirow{4}{*}{$K_2$} & 
    a & \multicolumn{4}{c||}{} \\
  & b & \multicolumn{4}{c||}{} \\
  & c & \multicolumn{4}{c||}{} \\
  & d & \multicolumn{4}{c||}{} \\  
\hline
\end{tabularx}

\end{document}

附录:以下是解决方案的样子:(a) 使用包的线条绘制宏booktabs,(b) 取消所有垂直规则和所有双重规则。正如老话所说,品味是无可争议的。不过,就我个人而言,我发现这个表格比带有大量水平和垂直规则的表格更容易让人接受。

在此处输入图片描述

\documentclass{article} % or some other suitable document class
\usepackage[T1]{fontenc}
\usepackage{tabularx,ragged2e,multirow}
\newcolumntype{C}{>{\Centering}X}
\usepackage{booktabs}
\begin{document}

\noindent
\begin{tabularx}{\textwidth}{@{} ll *{8}{C} @{}}
\toprule
  &   & \multicolumn{4}{c}{A} & \multicolumn{4}{c@{}}{B} \\
\cmidrule(lr){3-6} \cmidrule(l){7-10}
  & p & I & II & III & IV & I & II & III & IV \\
\midrule
\multirow{4}{*}{$K_1$} & 
    a  \\ 
  & b  \\ 
  & c  \\ 
  & d  \\
\midrule
\multirow{4}{*}{$K_2$} & 
    a  \\
  & b  \\
  & c  \\
  & d  \\  
\bottomrule
\end{tabularx}

\end{document}

相关内容