Latex 表,將一列分成兩列,並具有多行選項

Latex 表,將一列分成兩列,並具有多行選項

我想建立多行表。這是基線表。

documentclass[prodmode,acmtecs]{acmsmall} % Aptara syntax
\usepackage[ruled]{algorithm2e}
\usepackage{multirow}

\begin{document}
\section{Introduction}

\begin{table}[!t]
    \tbl{The caption.\label{cap}}
    {\begin{tabular}{p{2.0cm}p{3.0cm}p{3.5cm}p{1.0cm}p{0.8cm}p{0.8cm}}
        \hline
        \textbf{Workload}   &  \textbf{Description}   &   \textbf{Input}   &   \textbf{Miss Ratio}   &    \textbf{MPKI}    &   \textbf{LPKI} \\
        \hline
           A  &  B  &  C  &  1  &  2  &  3 \\
        \hline
           D  &  E  &  F  &  4  &  5  &  6  \\
        \hline
           G  &  H  &  I  &  7  &  8  &  9 \\
        \hline
           J  &  K  &  L  &  10 &  11 &  12  \\
        \hline
           M  &  N  &  O  &  13 &  14 &  15  \\
        \hline
           P  &  Q  &  R  &  16 &  17 &  18  \\
        \hline\hline
           S  &  T  &  U  &  19 &  20 &  21 \\
        \hline
           V  &  W  &  X  &  22 &  23 &  24  \\
        \hline
           Y  &  Z  & AA  &  25 &  26 &  27 \\
        \hline
          AB  & AC  & AD  &  28 &  28 &  29 \\
        \hline
          AE  & AF  & AG  &  30 &  31 &  32  \\
        \hline
          AH  & AI  & AJ  &  33 &  34 &  35 \\
        \hline\hline
          AK  & AL  & AM  &  36 &  37 &  38  \\
        \hline
          AN  & AO  & AP  &  39 &  40 & 41 \\
        \hline
    \end{tabular}}
\end{table}

\medskip
\end{document}

輸出是

在此輸入影像描述

現在我想將該workload列分成兩列。像這樣的東西

 +-----------------+---- 
 |     workload    
 +----------+-----------
 |          |  A   
 |          |  D   
 |  group1  |  G   
 |          |  J   
 |          |  M   
 |          |  P   
 -----------------------
 -----------------------
 |          |  S   
 |          |  V   
 |  group2  |  Y   
 |          |  AB   
 |          |  AE  
 |          |  AH   
 -----------------------
 -----------------------
 |          |  AK   
 | group3   |  AN   
 -----------------------  

因此,我透過將 6{}p 增加到 7p{} 在表格行上新增了另一列,並新增了這些行

 \multirow{6}{*}{group1}  &  A   &    B  &  C   &   1  &    2  &   3 \\
  ...
 \multirow{6}{*}{group2}  &  S   &   T   &  U   &  19  &   20  & 21 \\
  ...
 \multirow{2}{*}{group3}  &  AK  &   AL  & AM   &  36  &   37  &  38  \\

但結果遠遠超出了預期。事實上,我沒有看到任何行跨度!

更新

應用答案中的方法並將 A、B... 替換為真實文字後,我看到以下輸出

在此輸入影像描述

相反\addlinespace,我使用了\hline.正如您所看到的,每組中的行之間都有間隙。

答案1

應使用水平線來建立內容,但右側的空白也可以起到同樣的作用。看看桌子,看起來很乾淨。請注意規則之前/之後的小空白。

在此輸入影像描述

siunitx幫助我們在小數點對齊數字。

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
{\begin{tabular}{lcccS[table-format=2]S[table-format=2]S[table-format=2]}
        \toprule
    \multicolumn{2}{c}{Workload} & {Description} & {Input} & {Miss Ratio} & {MPKI} & {LPKI} \\
        \midrule
                   & A          & B             & C       & 1            & 2      & 3 \\
                   & D          & E             & F       & 4            & 5      & 6  \\
       group1      & G          & H             & I       & 7            & 8      & 9 \\
                   & J          & K             & L       & 10           & 11     & 12  \\
                   & M          & N             & O       & 13           & 14     & 15  \\
                   & P          & Q             & R       & 16 &               17     & 18  \\\addlinespace[1.3ex]
                   & S          & T             & U       & 19           & 20     & 21 \\
                   & V          & W             & X       & 22           & 23     & 24  \\
        group2     & Y          & Z             & AA      & 25           & 26     & 27 \\
                   & AB         & AC            & AD      & 28           & 28     & 29 \\
                   & AE         & AF            & AG      & 30           & 31     & 32  \\
                   & AH         & AI            & AJ      & 33 &               34     & 35 \\\addlinespace[1.3ex]
         group3    & AK         & AL            & AM      & 36           & 37     & 38  \\
                   & AN         & AO            & AP      & 39           & 40     & 41 \\
           \bottomrule
    \end{tabular}}
\end{document}

我不太確定我明白這個問題。我試著建構一個情境,但沒有成功。現在我無法重現這種行為。請注意,這multirow總是需要體力勞動。請注意,我使用了\midrules再次為了他們更好的間距。

請考慮以下事項

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{multirow}
\usepackage{array}
\newcolumntype{L}{>{\raggedright\arraybackslash}p{2.5cm}}
\begin{document}
{\begin{tabular}{lLLLS[table-format=2]S[table-format=2]S[table-format=2]}
        \toprule
    \multicolumn{2}{c}{Workload}                 & {Description}  & {Input} & {Miss Ratio} & {MPKI} & {LPKI} \\
        \midrule \multirow{15}{*}{\rotatebox{90}{group1}}      & Lions are pretty big              & Every lock has its key       & Canada is a country.             & 1      & 2         & 3 \\
                                               & some useful information here              & E       & F            & 4      & 5         & 6  \\
                                               & Why did the duck cross the road?              & H       & I            & 7      & 8         & 9 \\
                                               & There are footprints on your back              & K        & L            & 10     & 11        & 12  \\
                                               & Did the lion eat the zebra?              & N       & O            & 13     & 14        & 15  \\
                                               & There's a cat on the window sill              & Q       & R            & 16     &
           17                                      & 18  \\\midrule
    & Lions are pretty big              & Every lock has its key       & Canada is a country.             & 1      & 2         & 3 \\
                                               & some useful information here              & E       & F            & 4      & 5         & 6  \\
                                               & Why did the duck cross the road?              & H       & I            & 7      & 8         & 9 \\
   group1                                                  & There are footprints on your back              & K        & L            & 10     & 11        & 12  \\
                                               & Did the lion eat the zebra?              & N       & O            & 13     & 14        & 15  \\
                                               & There's a cat on the window sill              & Q       & R            & 16     &
           17                                      & 18  \\\midrule
           \multirow{6}{*}{\rotatebox{90}{group2}} & S              & T       & U            & 19     & 20        & 21 \\
                                               & V              & W       & X            & 22     & 23        & 24  \\
                                               & Y              & Z       & AA           & 25     & 26        & 27 \\
                                               & AB             & AC      & AD           & 28     & 28        & 29 \\
                                               & AE             & AF      & AG           & 30     & 31        & 32  \\
                                               & AH             & AI      & AJ           & 33     &
           34                                      & 35 \\\midrule
    \multirow{2}{*}{group3}                     & AK             & AL      & AM           & 36     & 37        & 38  \\
                                               & AN             & AO      & AP           & 39     & 40        & 41 \\
           \bottomrule
    \end{tabular}}
\end{document}

相關內容