带有垂直文本的表格和 \multicolumn

带有垂直文本的表格和 \multicolumn

我想要制作一个如下所示的表格:

必填表

我试过这个代码但是它给了我一些奇怪的

  \documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{rotating}
\usepackage[table]{xcolor}
\usepackage{xcolor}
\usepackage{multirow}
\usepackage{multicol}



\begin{document}

\begin{table}[htbp]
  \centering
  \caption{my table}
    \begin{tabular}{|ccc|c|l|}
    \toprule
    \rowcolor[rgb]{ .949,  .949,  .949} \multicolumn{1}{|c|}{\multirow{4}[8]{*}{\textcolor[rgb]{ .247,  .247,  .247}{\begin{sideways}\textbf{Household}\end{sideways}}}} & \multirow{3}[6]{*}{\cellcolor[rgb]{ 1,  1,  1}} & \multicolumn{1}{c}{\multirow{6}[12]{*}{\cellcolor[rgb]{ 1,  1,  1}}} & \multirow{10}[20]{*}{\cellcolor[rgb]{ 1,  1,  1}} & \cellcolor[rgb]{ 1,  1,  1}Peer pressure/prestige among parents \\
\cmidrule{5-5}    \rowcolor[rgb]{ .949,  .949,  .949} \multicolumn{1}{|c|}{} &       & \multicolumn{1}{c}{} &       & \cellcolor[rgb]{ 1,  1,  1}Economic status \\
\cmidrule{5-5}    \rowcolor[rgb]{ .949,  .949,  .949} \multicolumn{1}{|c|}{} &       & \multicolumn{1}{c}{} &       & \cellcolor[rgb]{ 1,  1,  1}Value placed on education \\
\cmidrule{2-2}\cmidrule{5-5}    \rowcolor[rgb]{ .949,  .949,  .949} \multicolumn{1}{|c|}{} & \multicolumn{1}{c|}{\multirow{4}[8]{*}{\textcolor[rgb]{ .247,  .247,  .247}{\begin{sideways}\textbf{Child}\end{sideways}}}} & \multicolumn{1}{c}{} &       & \cellcolor[rgb]{ 1,  1,  1}Aspirations \\
\cmidrule{1-1}\cmidrule{5-5}    \multicolumn{1}{|c}{\multirow{9}[18]{*}{}} & \multicolumn{1}{c|}{} & \multicolumn{1}{c}{} &       & Ability \\
\cmidrule{5-5}    \multicolumn{1}{|c}{} & \multicolumn{1}{c|}{} & \multicolumn{1}{c}{} &       & Academic performance \\
\cmidrule{3-3}\cmidrule{5-5}    \multicolumn{1}{|c}{} & \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{\multirow{5}[10]{*}{\cellcolor[rgb]{ .949,  .949,  .949}\textcolor[rgb]{ .247,  .247,  .247}{\begin{sideways}\textbf{Schooling/ teaching quality}\end{sideways}}}} &       & Exam-orientation, emphasis on scores \\
\cmidrule{2-2}\cmidrule{5-5}          & \multicolumn{1}{c}{\multirow{6}[12]{*}{}} &       &       & Inadequacy of schooling \\
\cmidrule{5-5}          & \multicolumn{1}{c}{} &       &       & \multicolumn{1}{p{20.355em}|}{Burden of non-academic tasks on teachers} \\
\cmidrule{5-5}          & \multicolumn{1}{c}{} &       &       & \multicolumn{1}{p{20.355em}|}{Recruitment/promotion unlinked to teaching performance} \\
\cmidrule{4-5}          & \multicolumn{1}{c}{} &       & \multicolumn{1}{c|}{\multirow{3}[6]{*}{\cellcolor[rgb]{ .949,  .949,  .949}\textcolor[rgb]{ .247,  .247,  .247}{\begin{sideways}\textbf{Cultural/ other factors}\end{sideways}}}} & Direct shirking/corruption by teachers \\
\cmidrule{3-3}\cmidrule{5-5}          &       & \multirow{2}[4]{*}{} &       & \multicolumn{1}{p{20.355em}|}{Labour market premium for elite colleges/professions} \\
\cmidrule{5-5}          &       &       &       & Herd mentality \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%

\end{document}

有人可以帮忙吗?

答案1

另一个不错的矩阵!

这并不奇怪:该nicematrix包本身提供了此表所需的所有元素。此外,代码简洁明了。

坦率地说,我喜欢一种可以让我花更多时间填写内容而不是格式化的工具。

使用的主要命令\Block允许识别和格式化多行/列单元格。(该命令\Block{}创建一个允许使用\\内部的单块单元格,从而在您想要的位置切割线条,而不是依赖于列的宽度。参见最后一行之前的 。)

请注意所有单元格都垂直居中。

该软件包需要两次编译(当格式更改时),有时会提到这不方便。如果您在单独的文件中开发表格,然后在最后阶段将文件放入主文档中,则不会出现这种情况。

x3

\documentclass{article}

\usepackage{nicematrix}

\begin{document}    

\begin{NiceTabular}{|wc{25pt}wc{25pt} wc{25pt} wc{25pt} |l|}[%
    cell-space-top-limit = 7pt,
    cell-space-bottom-limit = 7pt,
    code-before = \rectanglecolor{gray!15}{1-1}{4-1},
    code-before = \rectanglecolor{gray!15}{4-2}{7-2},
    code-before = \rectanglecolor{gray!15}{7-3}{11-3},
    code-before = \rectanglecolor{gray!15}{11-4}{17-4}, 
    ]
     \hline
    \rotate\Block[draw=black]{4-1}{\bfseries Household} & \Block{3-1}{}& \Block{6-1}{} & \Block{10-1}{} & Peer pressure/prestige among parents\\\cline{5-5}
    & & & & Economic status \\\cline{5-5}
    & & & & Value placed on education\\\cline{5-5}
    &\rotate \Block[draw=black]{4-1}{\bfseries Child  }& & & Aspirations \\\cline{5-5}
    \Block{9-1}{}&  & & & Ability \\\cline{5-5}
    & & & & Academic performance \\\cline{5-5}
    & &\rotate\Block[draw=black]{5-1}{\bfseries Schooling/  teaching quality}& & Exam-orientation, emphasis on scores \\\cline{5-5}
    & \Block{6-1}{} & & & Inadequacy of schooling \\\cline{5-5}
    & & & & \Block{}{Burden od non--academic tasks on \\ teachers} \\\cline{5-5}
    & & & &  \Block{}{Recruitment/promotion unlinked to \\teaching performance} \\\cline{5-5}
    & & &\rotate\Block[draw=black]{3-1}{\bfseries Cultural/ \\ \bfseries other factors}  & Direct shirking/corruption by teachers \\\cline{5-5}
    & &  \Block{2-1}{} & & \Block{}{Labour market premium for elite \\ colleges/professions} \\\cline{5-5}
    & & & &  Herd mentality \\
     \hline
\end{NiceTabular}

\end{document}

答案2

借助nicematrix(需要版本 5.8):

在此处输入图片描述

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\noindent
\NiceMatrixOptions{cell-space-top-limit = 3pt,cell-space-bottom-limit = 3pt}
\begin{NiceTabular}{c c c c | p{7.25cm}|}
\cline{5-5}
\Block[fill=lightgray, draw=black]{4-1}{\rotate Household}  & &  &                      & Peer pressure/prestige among parents                   \\ \cline{5-5}
   & & &                                                                                & Economic status                                        \\ \cline{5-5}
   & & &                                                                                & Value placed on education                              \\ \cline{5-5}
   & \Block[fill=lightgray, draw=black]{4-1}{\rotate Child} & &                         & Aspirations                                            \\ \cline{5-5}
   & & &                                                                                & Ability                                                \\ \cline{5-5}
   & & &                                                                                & Academic performance                                   \\ \cline{5-5}
   & & \Block[fill=lightgray, draw=black]{5-1}{\rotate Schooling/\\ teaching quality} & & Exam-orientation, emphasis on scores                   \\ \cline{5-5}
   & & &                                                                                & Inadequacy of schooling                                \\ \cline{5-5}
   & & &                                                                                & Burden of non-academic tasks on teachers               \\ \cline{5-5}
   & & &                                                                                & Recruitment/promotion unlinked to teaching performance \\ \cline{5-5} 
   & & & \Block[fill=lightgray, draw=black]{3-1}{\rotate Cultural/\\ other factors}     & Direct shirking/corruption by teachers                 \\ \cline{5-5}
   & & &                                                                                & Labour market premium for elite colleges/professions   \\ \cline{5-5}
   & & &                                                                                & Herd mentality                                         \\ \cline{5-5}
\end{NiceTabular}
\end{document}

答案3

这个答案是 leandriis 答案的一个小变体。我使用了 key hvlines(由 提供nicematrix)来绘制所有规则。由于我不想在前四列中使用内部规则,因此我\Block为这四列设置了一个全局规则:(\Block{-4}{}语法-4意味着?-44 列和所有剩余行)。

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\noindent
\NiceMatrixOptions{cell-space-limits = 3pt}
\begin{NiceTabular}{c c c c >{\arraybackslash}p{7.25cm}}[hvlines]
\Block{-4}{}
\Block[fill=lightgray, draw=black]{4-1}{\rotate Household}  & &  &                      & Peer pressure/prestige among parents                   \\
   & & &                                                                                & Economic status                                        \\
   & & &                                                                                & Value placed on education                              \\
   & \Block[fill=lightgray, draw=black]{4-1}{\rotate Child} & &                         & Aspirations                                            \\
   & & &                                                                                & Ability                                                \\
   & & &                                                                                & Academic performance                                   \\
   & & \Block[fill=lightgray, draw=black]{5-1}{\rotate Schooling/\\ teaching quality} & & Exam-orientation, emphasis on scores                   \\
   & & &                                                                                & Inadequacy of schooling                                \\
   & & &                                                                                & Burden of non-academic tasks on teachers               \\
   & & &                                                                                & Recruitment/promotion unlinked to teaching performance \\ 
   & & & \Block[fill=lightgray, draw=black]{3-1}{\rotate Cultural/\\ other factors}     & Direct shirking/corruption by teachers                 \\
   & & &                                                                                & Labour market premium for elite colleges/professions   \\
   & & &                                                                                & Herd mentality                                         \\
\end{NiceTabular}
\end{document}

上述代码的输出

相关内容