多列表格,每行的列数不同

多列表格,每行的列数不同

我想为我的本科论文重现下表(文献综述的分类法参见 Cooper):

Cooper 分类法

我第一次尝试使用包中的多列功能创建一个表multirow 。我使用了 15 列,因此“特征”列等于 3 列,每行剩下的 12 列适合一行 3 个项目(等于 4 个多列)和 4 个项目(等于 3 个多列)。

所以我生成(1)和(2)行的第一个方法是:

\usepackage{multirow}
\definecolor{gray}{RGB}{224,224,224}
\begin{figure}
   \centering
   \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
      \hline
      \multicolumn{3}{|>{\columncolor{gray}}c|}{focus} & 
      \multicolumn{3}{|>{\columncolor{gray}}c|}{research outcomes} &
      \multicolumn{3}{|>{\columncolor{gray}}c|}{research methods} & 
      \multicolumn{3}{|>{\columncolor{gray}}c|}{theories} & 
      \multicolumn{3}{|>{\columncolor{gray}}c|}{applications}\\
      \hline
      \multicolumn{3}{|>{\columncolor{gray}}c|}{goal} & 
      \multicolumn{4}{|>{\columncolor{gray}}c|}{integration} &
      \multicolumn{4}{|>{\columncolor{gray}}c|}{critisism} & 
      \multicolumn{4}{|>{\columncolor{gray}}c|}{central issues}\\
      \hline
   \end{tabular}
   \caption{Test}
   \label{fig:test}
\end{figure}

哪个产生了

在此处输入图片描述

我也尝试使用 tabularx 环境进行同样的操作,但结果很奇怪。

使用多列来生成该表是否具有很好的可能性?

答案1

关于使用,multicolumn您可以使用以下方法,根据文本宽度和序言中必须指定的第一列中最宽的条目自动计算列的宽度。

\documentclass{article}
\usepackage{geometry}

\usepackage{calc}



\newlength{\longestentry}
\setlength{\longestentry}{\widthof{focus}}

\newlength{\mytablewidth}
\setlength{\mytablewidth}{\textwidth-\longestentry-2\tabcolsep-2\arrayrulewidth}

\newcolumntype{T}{>{\centering\arraybackslash}p{0.33\mytablewidth-2\tabcolsep-\arrayrulewidth}}
\newcolumntype{F}{>{\centering\arraybackslash}p{0.25\mytablewidth-2\tabcolsep-\arrayrulewidth}}


\begin{document}
\noindent
   \begin{tabular}{|p{\longestentry}cccccccccccc}
      \hline
      focus & 
      \multicolumn{3}{|F|}{research outcomes} &
      \multicolumn{3}{F|}{research methods} & 
      \multicolumn{3}{F|}{theories} & 
      \multicolumn{3}{F|}{applications}\\
      \hline
      goal & 
      \multicolumn{4}{|T|}{integration} &
      \multicolumn{4}{T|}{critisism} & 
      \multicolumn{4}{T|}{central issues}\\
      \hline
   \end{tabular}


\end{document}

在此处输入图片描述


以下是更完整的 MWE,其中包括问题中显示的所需输出的更多功能(例如颜色、用于分隔列和行的空白以及自动行编号

\documentclass{article}


\usepackage[table]{xcolor}
\usepackage{calc}
\usepackage{etoolbox}
\usepackage{array, hhline}


%%%%% longest entry of the caracteristic column %%%%%
\newlength{\longestentry}
\setlength{\longestentry}{\widthof{organisation}}

%%%%% Automatic row numbering %%%%%
\preto\tabular{\setcounter{magicrownumbers}{0}}
\newcounter{magicrownumbers}
\newcommand\rownumber{\stepcounter{magicrownumbers}\arabic{magicrownumbers}}
\newlength{\rownumberwidth}
\setlength{\rownumberwidth}{2.25em}
\newcommand{\insertrownumber}{\makebox[\rownumberwidth][r]{\bfseries(\rownumber)\space}}

%%%%% calculates the width that is left for the category columns %%%%%
\newlength{\mytablewidth}
\setlength{\mytablewidth}{\textwidth-\longestentry-2\tabcolsep-4\arrayrulewidth-4pt-\rownumberwidth}

%%%%% Introduces three new table column types and three new commands for the categroy cells %%%%%
\newcolumntype{T}{>{\centering\arraybackslash}m{0.33\mytablewidth-2\tabcolsep-\arrayrulewidth}}
\newcolumntype{F}{>{\centering\arraybackslash}m{0.25\mytablewidth-2\tabcolsep-\arrayrulewidth}}
\newcolumntype{O}{>{\centering\arraybackslash}m{0.5\mytablewidth-2\tabcolsep-\arrayrulewidth}}
\newcommand{\halfentry}[1]{\multicolumn{6}{O|}{#1}}
\newcommand{\thirdentry}[1]{\multicolumn{4}{T|}{#1}}
\newcommand{\fourthentry}[1]{\multicolumn{3}{F|}{#1}}


%%%%% Settings for horizontal lines and cellcolor %%%%%
\setlength{\doublerulesep }{4pt}
\doublerulesepcolor{white}
\newcommand{\myhline}{\hhline{-~------------}}
\newcommand{\mywhitehline}{\hhline{~~------------}\hhline{=}\hhline{~~------------}}
\definecolor{gray}{RGB}{224,224,224}


\begin{document}
\noindent
   \begin{tabular}{|@{\insertrownumber}|m{\longestentry}|@{}m{4pt}@{}|cccccccccccc}
      \myhline
      \multicolumn{1}{|>{\centering\arraybackslash}m{2.25em+\longestentry+\arrayrulewidth}|}{Characteristic} & &
      \multicolumn{12}{>{\centering\arraybackslash}m{\mytablewidth-2\tabcolsep}|}{Category}\\ %
      \mywhitehline
       focus & &
      \fourthentry{research outcomes} &
      \fourthentry{\cellcolor{gray} research methods} & 
      \fourthentry{theories} & 
      \fourthentry{applications}\\
      \myhline
       goal & &
      \thirdentry{integration} &
      \thirdentry{\cellcolor{gray}critisism} & 
      \thirdentry{central issues}\\
      \myhline
       organisation &  &
      \thirdentry{historical} &
      \thirdentry{conseptual} & 
      \thirdentry{methodological}\\
      \myhline
       perspective &  &
      \halfentry{neutral representation} &
      \halfentry{\cellcolor{gray}espousal of position}\\
      \myhline
   \end{tabular}


\end{document}

在此处输入图片描述

相关内容