如何在表格中每行有不同数量的列?

如何在表格中每行有不同数量的列?

我正在尝试构建一个像图片中的表格。我尝试使用 \multicolumn 方法,但是我发现很难从一行有 4 列的行转到下一行有 3 列的行。有没有什么想法可以构建它?

我查看了论坛上的其他解决方案,但都是从 4 变为 2、从 6 变为 2/2/2 或类似的。我还没有看到从 4 变为 3 的方案。

以下是我使用的代码:

\begin{table}[]
\centering
\begin{tabular}{|c|c|c|c|c|c|c|}
%\cline{1-1} \cline{3-7}
\multicolumn{2}{c}{Characteristics} & & \multicolumn{4}{|c|}{Categories} \\
\cline{0-1} \cline{4-7} \cline{0-1} \cline{4-7}
1 & Focus & & Research Outcomes & Research Methods & Theories & Applications \\ \cline{0-1} \cline{4-7}
2 & Goal & & \multicolumn{4}{c|}{\begin{tabular}{l|c|r} Integration & Criticism & Central issue\end{tabular}} \\
\cline{0-1} \cline{4-7}
3 & Organization & & \multicolumn{4}{c|}{\begin{tabular}{l|c|r}  Historical & Conceptual & Methodological\end{tabular}} \\
\cline{0-1} \cline{4-7}
4 & Perspective & & \multicolumn{2}{c|}{Neutral representation} & \multicolumn{2}{c|}{Espousal of position} \\ \cline{0-1} \cline{4-7}
5 & Audience & & Specialized scholars & General scholars & Practitioners /Politicians & General Public \\ 
\cline{0-1} \cline{4-7}
6 & Coverage & & Exhaustive & Exhaustive and selective & Representative & Central / pivotal \\
\cline{0-1} \cline{4-7}

\end{tabular}
\caption{Taxonomy of literature reviews based on Cooper method \footcite{Cooper1988OrganizingReviews}}
\label{tab:my_label}
\end{table}

提前致谢。

期望输出

要构建的表

我的代码输出

代码输出

答案1

在此处输入图片描述

\documentclass{article}

\begin{document}


\begin{tabular}{cccccc}
1&2&3&4&5&6\\
 \multicolumn{1}{|c|}{ONE}&
 \multicolumn{2}{c|}{TWO}&
 \multicolumn{2}{c|}{THREE}&
 \multicolumn{1}{|c|}{FOUR}\\
\hline
 \multicolumn{2}{|c|}{one}&
 \multicolumn{2}{c|}{two}&
 \multicolumn{2}{c|}{three}
\end{tabular}
\end{document}

只需确保表格有足够的列来容纳所有可能的单元格跨度。

答案2

以下是我对 的看法tabularray。语法一开始有点繁琐,但之后可以很方便地进行调整以适应自己的口味。

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}

\begin{tblr}{
    colspec={*{9}{c}},
    cell{1}{1}={c=2}{c, gray},
    cell{1}{4}={c=6}{c, gray},
    cell{1}{1,4}={fg=white},
    cell{3}{4}={bg=lightgray},
    cell{3}{5,7}={c=2}{c},
    cell{3}{9}={bg=lightgray},
    cell{4}{4}={bg=lightgray},
    cell{5}{6}={bg=lightgray},
    cell{4-5}{4,6,8}={c=2}{c},
    cell{6}{4}={c=3}{c, bg=lightgray},
    cell{6}{7}={c=3}{c},
    vline{1-10}={1,3-6}{solid},
    hline{1-7}={1,2,4-9}{solid},
    row{1,3-6}={ht=0.5cm},
    row{2}={ht=0.1cm},
    rows={m},
    stretch=0
    }
Characteristic & & & Categories\\
\ \\
1 & Focus & & {Research\\ outcome} & {Research\\ methods} & & Theories & & Applications\\
2 & Goal & & Integration & & Criticism & & Central issue\\
3 & Organization & & Historical & & Conceptual & & Methodological\\
4 & Perspective & & Neutral representation & & & Espousal of position\\
\end{tblr}

\end{document}

我只做了前四行,其他行没有什么新内容。 结果

答案3

请参阅下面的更新版本


版本 1

@David Carlisle 谢谢您的快速回答。

对于可能感兴趣的人,以下是我制作它的方法。

\begin{table}[]
    \centering
    \begin{tabular}{|c|c|c|c|c|c|c|}
    \cline{0-1} \cline{4-7}
    \multicolumn{2}{|c|}{\cellcolor[HTML]{616161} \textcolor{white}{Characteristics}} & & \multicolumn{4}{|c|}{\cellcolor[HTML]{616161} \textcolor{white}{Categories}} \\
    \cline{0-1} \cline{4-7}
    1 & Focus & & \cellcolor[HTML]{C0C0C0}Research Outcomes & Research Methods & Theories & \cellcolor[HTML]{C0C0C0}Applications \\ \cline{0-1} \cline{4-7}
    2 & Goal & & \multicolumn{1}{c}{\cellcolor[HTML]{C0C0C0}Integration} & \multicolumn{2}{|c|}{Criticism} & \multicolumn{1}{c|}{Central issue} \\ \cline{0-1} \cline{4-7}
    3 & Organization & & \multicolumn{1}{c}{Historical} & \multicolumn{2}{|c|}{\cellcolor[HTML]{C0C0C0}Conceptual} & \multicolumn{1}{c|}{Methodological} \\ \cline{0-1} \cline{4-7}
    4 & Perspective & & \multicolumn{2}{c|}{\cellcolor[HTML]{C0C0C0}Neutral representation} & \multicolumn{2}{c|}{Espousal of position} \\ \cline{0-1} \cline{4-7}
    5 & Audience & & \cellcolor[HTML]{C0C0C0}Specialized scholars & General scholars & Practitioners /Politicians & General Public \\ 
    \cline{0-1} \cline{4-7}
    6 & Coverage & & \cellcolor[HTML]{C0C0C0}Exhaustive & Exhaustive and selective & Representative & Central / pivotal \\
    \cline{0-1} \cline{4-7}
    
    \end{tabular}
    \caption{Taxonomy of literature reviews based on Cooper method \footcite{Cooper1988OrganizingReviews}}
    \label{tab:my_label}
\end{table}

在此处输入图片描述


版本 2

更新:

感谢@Rmano 的提示

\begin{table}[]
    \centering
    \resizebox{\columnwidth}{!}{
    \begin{tabular}{ccc*{12}{wc{1cm}}}
    \cline{0-1} \cline{4-15}
    \multicolumn{2}{|c|}{\cellcolor[HTML]{616161} \textcolor{white}{Characteristics}} & & \multicolumn{12}{|c|}{\cellcolor[HTML]{616161} \textcolor{white}{Categories}} \\
    \cline{0-1} \cline{4-15}
    \multicolumn{1}{|c}{1} & \multicolumn{1}{|c|}{Focus} & & \multicolumn{3}{|c}{Research Outcomes} & \multicolumn{3}{|c}{Research Methods} & \multicolumn{3}{|c}{Theories} & \multicolumn{3}{|c|}{\cellcolor[HTML]{C0C0C0}Applications} \\
    \cline{0-1} \cline{4-15}

    \multicolumn{1}{|c}{2} & \multicolumn{1}{|c|}{Goal}  & & \multicolumn{4}{|c|}{\cellcolor[HTML]{C0C0C0}Integration} & \multicolumn{4}{c}{Criticism} & \multicolumn{4}{|c|}{Central issue} \\ \cline{0-1} \cline{4-15}
    
    \multicolumn{1}{|c}{3} & \multicolumn{1}{|c|}{Organization} & & \multicolumn{4}{|c}{Historical} & \multicolumn{4}{|c}{\cellcolor[HTML]{C0C0C0}Conceptual} & \multicolumn{4}{|c|}{Methodological} \\ 
    \cline{0-1} \cline{4-15}
    
    \multicolumn{1}{|c}{4} & \multicolumn{1}{|c|}{Perspective} & & \multicolumn{6}{|c}{\cellcolor[HTML]{C0C0C0}Neutral representation} & \multicolumn{6}{|c|}{Espousal of position} \\ 
    \cline{0-1} \cline{4-15}
    
    \multicolumn{1}{|c}{5} & \multicolumn{1}{|c|}{Audience} & & \multicolumn{3}{|c}{\cellcolor[HTML]{C0C0C0}Specialized scholars} & \multicolumn{3}{|c}{General scholars} & \multicolumn{3}{|c}{Practitioners / Politicians} & \multicolumn{3}{|c|}{General Public} \\
    \cline{0-1} \cline{4-15}
    
    \multicolumn{1}{|c}{6} & \multicolumn{1}{|c|}{Coverage} & & \multicolumn{3}{|c}{\cellcolor[HTML]{C0C0C0}Exhaustive} & \multicolumn{3}{|c}{Exhaustive and selective} & \multicolumn{3}{|c}{Representative} & \multicolumn{3}{|c|}{Central / pivotal} \\
    \cline{0-1} \cline{4-15}
    &&&&&&&&&&&&&& \\
    
    \end{tabular}}
    \caption{Taxonomy of literature reviews based on Cooper method \footcite{Cooper1988OrganizingReviews}}
    \label{tab:slr_taxonomy}
\end{table}

在此处输入图片描述

相关内容