将表格分成两列

将表格分成两列

我有一张很长(顺便说一下,不到一页)且很窄的表格;为了节省空间,我希望将它放在两列上。参考下图,我希望将前 8 个条目与第 9-16 个条目并排显示(请注意,添加字母“A”、“B”等是为了便于阅读代码,在原始表格中,“schema”列包含一个可增加行高的图像)。

示例结果

示例代码如下:

\documentclass[a4paper]{report}

\usepackage{booktabs}
\usepackage{fullpage}
\usepackage{multirow}
\usepackage[table]{xcolor}
\usepackage{array}
\usepackage[pdftex]{graphicx}

\begin{document}

\begin{table}[htbp]
  \centering
    \begin{tabular}{llp{0.1cm}p{0.1cm}p{0.1cm}p{0.1cm}lp{3cm}}
    \toprule
& & \multicolumn{4}{c}{Parameter} & & \\
ID & Schema & F & E & P & N & \multicolumn{2}{l}{Cluster}\\
    \midrule
1 & A & H & H & H & H & 1 & High performer\\
2 & B & H & H & H & L & 2 & Cash provider\\
3 & C & H & H & L & H & 3 & Alternative means of financing\\
4 & D & H & H & L & L & 4 & Doubtful case\\
5 & E & H & L & H & H & 5 & Low performer\\
6 & F & H & L & H & L & 5 & Low performer\\
7 & G & H & L & L & H & 6 & Possible AMF\\
8 & H & H & L & L & L & 5 & Low performer\\
9 & I & L & H & H & H & 7 & Cash flow optimization\\
10 & L & L & H & H & L & 7 & Cash flow optimization\\
11 & M & L & H & L & H & 8 & SCF needy\\
12 & N & L & H & L & L & 7 & Cash flow optimization\\
13 & O & L & L & H & H & 4 & Doubtful case\\
14 & P & L & L & H & L & 9 & Potential cash provider\\
15 & Q & L & L & L & H & 5 & Low performer\\
16 & R & L & L & L & L & 5 & Low performer\\
    \bottomrule
    \end{tabular}%
  \caption{Cluster identification.}
  \label{clusteridentification}%
\end{table}%

\end{document}

好的,现在我知道这个问题有不同的解决方案:

  • 第一个方法是将表格“加倍”,其标题如下所示:

    \toprule
    & & \multicolumn{4}{c}{Parameter} & & & & \multicolumn{4}{c}{Parameter} & & \\
    ID & Schema & F & E & P & N & \multicolumn{2}{l}{Cluster} ID & Schema & F & E & P & N & \multicolumn{2}{l}{Cluster}\\
    \midrule

    无论如何,这种解决方案不太灵活,将来操作表格也不方便(而且很可能我不得不这样做,而且这么说吧:它很丑陋)

  • 不讨论双列环境,因为页面的其余部分必须与文档的其余部分一样写在一列上。

  • minipage 结构给 \table 环境带来了问题:我无法编译该文档!

答案1

当我写下我的问题时,我找到了解决方案。如果我理解正确的话,这个(相当棒的)网站的用户会鼓励他们自己回答问题,因此,即使我认为我的问题很简单,我还是想说:

minipage 构造就是解决方案:它只需要之内表环境。实现我期望的正确代码是:

\begin{table}
\begin{minipage}[t]{0.5\linewidth}
    \begin{tabular}[t]{llp{0.1cm}p{0.1cm}p{0.1cm}p{0.1cm}lp{3cm}}
    \toprule
& & \multicolumn{4}{c}{Parameter} & & \\
ID & Schema & F & E & P & N & \multicolumn{2}{l}{Cluster}\\
    \midrule
1 & A & H & H & H & H & 1 & High performer\\
2 & B & H & H & H & L & 2 & Cash provider\\
3 & C & H & H & L & H & 3 & Alternative means of financing\\
4 & D & H & H & L & L & 4 & Doubtful case\\
5 & E & H & L & H & H & 5 & Low performer\\
6 & F & H & L & H & L & 5 & Low performer\\
7 & G & H & L & L & H & 6 & Possible AMF\\
8 & H & H & L & L & L & 5 & Low performer\\
    \bottomrule
    \end{tabular}%
\end{minipage}
\begin{minipage}[t]{0.5\linewidth}
    \begin{tabular}[t]{llp{0.1cm}p{0.1cm}p{0.1cm}p{0.1cm}lp{3cm}}
    \toprule
& & \multicolumn{4}{c}{Parameter} & & \\
ID & Schema & F & E & P & N & \multicolumn{2}{l}{Cluster}\\
    \midrule
9 & I & L & H & H & H & 7 & Cash flow optimization\\
10 & L & L & H & H & L & 7 & Cash flow optimization\\
11 & M & L & H & L & H & 8 & SCF needy\\
12 & N & L & H & L & L & 7 & Cash flow optimization\\
13 & O & L & L & H & H & 4 & Doubtful case\\
14 & P & L & L & H & L & 9 & Potential cash provider\\
15 & Q & L & L & L & H & 5 & Low performer\\
16 & R & L & L & L & L & 5 & Low performer\\
    \bottomrule
    \end{tabular}%
\end{minipage}
\caption{caption}
\end{table}

当然,需要进行一些小的调整以适合文本,但它是有效的。

答案2

唯一一个换行符似乎有意义的列(实际上,似乎是必需的!)是最后一列。因此,我建议您使用两个并排的minipage环境,每个环境包含一个tabular具有多个类型 列的环境p,而不是提供两个并排的tabularx环境,每个环境包含一个具有多个类型 列的环境,其中七列为 类型l,最后一列为 类型X

我还将为标题材料提供更多的视觉结构。

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage{tabularx,booktabs,ragged2e}
\usepackage[a4paper,margin=2.5cm]{geometry} % <-- choose suitable text block parameters

\begin{document}
\begin{table}
\setlength{\tabcolsep}{3pt} % default value is 6pt
\begin{tabularx}{0.48\textwidth}[t]{@{}*{7}{l}>{\RaggedRight}X@{}}
\toprule
ID & Schema & \multicolumn{4}{c}{Parameter} & \multicolumn{2}{l}{Cluster}\\
\cmidrule{3-6}
& & F & E & P & N \\
\midrule
1 & A & H & H & H & H & 1 & High performer\\
2 & B & H & H & H & L & 2 & Cash provider\\
3 & C & H & H & L & H & 3 & Alternative means of financing\\
4 & D & H & H & L & L & 4 & Doubtful case\\
5 & E & H & L & H & H & 5 & Low performer\\
6 & F & H & L & H & L & 5 & Low performer\\
7 & G & H & L & L & H & 6 & Possible AMF\\
8 & H & H & L & L & L & 5 & Low performer\\
\bottomrule
\end{tabularx}%
\hspace*{\fill} % maximize separation between the tabulars
\begin{tabularx}{0.48\textwidth}[t]{@{}*{7}{l}>{\RaggedRight}X@{}}
\toprule
ID & Schema & \multicolumn{4}{c}{Parameter} & \multicolumn{2}{l}{Cluster}\\
\cmidrule{3-6}
& & F & E & P & N \\
\midrule
9 & I & L & H & H & H & 7 & Cash flow optimization\\
10 & L & L & H & H & L & 7 & Cash flow optimization\\
11 & M & L & H & L & H & 8 & SCF needy\\
12 & N & L & H & L & L & 7 & Cash flow optimization\\
13 & O & L & L & H & H & 4 & Doubtful case\\
14 & P & L & L & H & L & 9 & Potential cash provider\\
15 & Q & L & L & L & H & 5 & Low performer\\
16 & R & L & L & L & L & 5 & Low performer\\
\bottomrule
\end{tabularx}

\caption{caption}
\end{table}
\end{document}

相关内容