将宽表分成两列

将宽表分成两列

我正在尝试将这张表格放入我的论文中。这篇论文分为两栏,所以我猜表格需要占据整个页面(这没问题)。我尝试将字体缩小并使用 {table*},但它仍然不适合页面或与其余文本重叠。

这是我的桌子:

\begin{table}[]
\begin{tabular}{lcccccccccccc}
\multicolumn{1}{c}{\textbf{F1-Values}} & \multicolumn{4}{c}{Naive Bayes}                      & \multicolumn{4}{c}{K-NN}                             & \multicolumn{4}{c}{Decision Tree}                    \\
\textbf{String Representation}         & \multicolumn{2}{c}{BoW} & \multicolumn{2}{c}{TF-IDF} & \multicolumn{2}{c}{BoW} & \multicolumn{2}{c}{TF-IDF} & \multicolumn{2}{c}{BoW} & \multicolumn{2}{c}{TF-IDF} \\
                                       & with       & without    & with        & without      & with       & without    & with        & without      & with       & without    & with        & without      \\
\textbf{Removal of Punctuation}        & 0,9750     & 0,9835     & 0,9373      & 0,9562       & 0,8723     & 0,8802     & 0,9543      & 0,9651       & 0,9641     & 0,9601     & 0,9394      & 0,9501       \\
\textbf{Removal of Stopwords}          & 0,9824     & 0,9835     & 0,9671      & 0,9562       & 0,8692     & 0,8802     & 0,8681      & 0,9651       & 0,9579     & 0,9641     & 0,9603      & 0,9501       \\
\textbf{Removal of Numbers}            & 0,9764     & 0,9835     & 0,9659      & 0,9671       & 0,8812     & 0,8802     & 0,9521      & 0,9651       & 0,9694     & 0,9641     & 0,9602      & 0,9603       \\
\textbf{Stemming}                      & 0,9787     & 0,9835     & 0,9541      & 0,9671       & 0,8640     & 0,8812     & 0,9312      & 0,9651       & 0,9576     & 0,9694     & 0,9508      & 0,9603      
\end{tabular}
\end{table}

我有点绝望而且着急,所以欢迎任何帮助。

答案1

  • 我的第一个答案版本来得太晚了,@Mico 用几乎相同的解决方案咬了我几十秒... :-(
  • 因此我使用该包重写了它,并tabularray使用比默认 cm 字体稍窄的字体,使其与默认 cm 字体略有不同。newtxtextnewtxmath
  • 该包tabularray提供了清晰简洁的表格编写语法,可以将表格设计与其内容分开。
  • 如果这个建议适合您,很难说,因为您没有提供重要信息,例如使用的文档类别、页面布局、字体等。
  • 如果这个建议不可接受,您应该考虑将桌子旋转为横向。
  • 梅威瑟:
\documentclass[twocolumn]{article}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{newtxtext, newtxmath}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
    \begin{table*}
    \small
\begin{tblr}{colsep = 3pt,
            colspec = {@{} Q[l, font=\bfseries]
                     *{12}{X[c]} 
                       @{}},
            cell{1}{2,6,10} = {c=4}{},
            cell{2}{even}   = {c=2}{},
           }
    \toprule
F1-Values   &   Naive Bayes 
                &   &   &   &   K-NN    
                                &   &   &   &   Decision Tree   
                                                &   &   &   \\
    \cmidrule[lr]{2-5}
    \cmidrule[lr]{6-9}
    \cmidrule[l]{10-13}
\SetCell[r=2]{} String Representation        
            &   BoW   
                &   &   TF-IDF
                        &   &   BoW
                                &   &   TF-IDF
                                        &   &   BoW
                                                &   &   TF-IDF
                                                        &   \\
    \cmidrule[lr]{2-3}  \cmidrule[lr]{4-5}
    \cmidrule[lr]{6-7}  \cmidrule[lr]{8-9}
    \cmidrule[lr]{10-11}   \cmidrule[l]{12-13}
     & with  & w/o   & with  & w/o 
            & with  & w/o   & with  & w/o
                            & with  & w/o   & with  & w/o   \\
    \midrule
Removal of Punctuation
    & 0,9750    & 0,9835    & 0,9373    & 0,9562    & 0,8723    & 0,8802     
    & 0,9543    & 0,9651    & 0,9641    & 0,9601    & 0,9394    & 0,9501    \\
Removal of Stopwords
    & 0,9824    & 0,9835    & 0,9671    & 0,9562    & 0,8692    & 0,8802     
    & 0,8681    & 0,9651    & 0,9579    & 0,9641    & 0,9603    & 0,9501    \\
Removal of Numbers
    & 0,9764    & 0,9835    & 0,9659    & 0,9671    & 0,8812    & 0,8802     
    & 0,9521    & 0,9651    & 0,9694    & 0,9641    & 0,9602    & 0,9603    \\
Stemming                      
    & 0,9787    & 0,9835    & 0,9541    & 0,9671    & 0,8640    & 0,8812     
    & 0,9312    & 0,9651    & 0,9576    & 0,9694    & 0,9508    & 0,9603    \\
    \bottomrule
\end{tblr}
    \end{table*}
\end{document}

在此处输入图片描述

(红线表示页面布局)

答案2

如果你在标题单元格中应用一些缩写,并且愿意放弃大胆的左侧列中的材料,仍然需要执行\small(字体大小线性减少 10%)才能使表格适合文本块。如下图屏幕截图中的第二个表格所示,使用包的机制siunitx将所有 12 个数据列中的所有数字四舍五入为 3 位小数,可以让你坚持使用默认字体大小,即\normalsize

两个问题:如果读者看到所有数字的小数点后第四位数字,他们应该得到什么信息?如果读者看到所有数字的四位小数,你有多确定他们真的能理解你希望他们得到的信息?

在此处输入图片描述

\documentclass[twocolumn]{article} % or some other suitable document class
\usepackage{booktabs} % for well-spaced horizontal rules
\usepackage{siunitx} % for 'S' column type, enable rounding of numbers

\begin{document}

\begin{table*} % use a 'table*' environment, which spans both columns

%%% first version: no rounding to three digits
\begingroup % localize scope of next two instructions
\small
\setlength\tabcolsep{0pt} % let LaTeX determine intercolumn whitespace

\caption{Keep all 4 digits, switch to \texttt{\string\small}}

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l *{12}{c} }
\toprule
F1-Values 
  & \multicolumn{4}{c}{Naive Bayes}                      
  & \multicolumn{4}{c}{K-NN}                             
  & \multicolumn{4}{c}{Decision Tree} \\
  \cmidrule{2-5} \cmidrule{6-9} \cmidrule{10-13} 
String Representation
  & \multicolumn{2}{c}{BoW} & \multicolumn{2}{c}{TF-IDF} 
  & \multicolumn{2}{c}{BoW} & \multicolumn{2}{c}{TF-IDF} 
  & \multicolumn{2}{c}{BoW} & \multicolumn{2}{c}{TF-IDF} \\
  \cmidrule{2-3} \cmidrule{4-5} 
  \cmidrule{6-7} \cmidrule{8-9} 
  \cmidrule{10-11} \cmidrule{12-13} 
  & with & w/o & with & w/o & with & w/o & with & w/o & with & w/o & with & w/o \\
\midrule
Remove Punctuation & 0,9750 & 0,9835 & 0,9373 & 0,9562 & 0,8723 & 0,8802 & 0,9543 & 0,9651 & 0,9641 & 0,9601 & 0,9394 & 0,9501 \\
Remove Stopwords   & 0,9824 & 0,9835 & 0,9671 & 0,9562 & 0,8692 & 0,8802 & 0,8681 & 0,9651 & 0,9579 & 0,9641 & 0,9603 & 0,9501 \\
Remove Numbers     & 0,9764 & 0,9835 & 0,9659 & 0,9671 & 0,8812 & 0,8802 & 0,9521 & 0,9651 & 0,9694 & 0,9641 & 0,9602 & 0,9603 \\
Stemming           & 0,9787 & 0,9835 & 0,9541 & 0,9671 & 0,8640 & 0,8812 & 0,9312 & 0,9651 & 0,9576 & 0,9694 & 0,9508 & 0,9603 \\
\bottomrule
\end{tabular*}
\endgroup

\bigskip
%%% second version: round to 3 decimal digits
\setlength\tabcolsep{0pt} % let LaTeX determine intercolumn whitespace

\caption{Round to 3 digits, keep default font size}

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} 
    l 
    *{12}{S[table-format=1.3, output-decimal-marker={,},
            round-mode=places, round-precision=3] }}
\toprule
F1-Values 
  & \multicolumn{4}{c}{Naive Bayes}                      
  & \multicolumn{4}{c}{K-NN}                             
  & \multicolumn{4}{c}{Decision Tree} \\
  \cmidrule{2-5} \cmidrule{6-9} \cmidrule{10-13} 
String Representation
  & \multicolumn{2}{c}{BoW} & \multicolumn{2}{c}{TF-IDF} 
  & \multicolumn{2}{c}{BoW} & \multicolumn{2}{c}{TF-IDF} 
  & \multicolumn{2}{c}{BoW} & \multicolumn{2}{c}{TF-IDF} \\
  \cmidrule{2-3} \cmidrule{4-5} 
  \cmidrule{6-7} \cmidrule{8-9} 
  \cmidrule{10-11} \cmidrule{12-13} 
  & {with} & {w/o} & {with} & {w/o} & {with} & {w/o} & {with} & {w/o} & {with} & {w/o} & {with} & {w/o} \\
\midrule
Remove Punctuation & 0,9750 & 0,9835 & 0,9373 & 0,9562 & 0,8723 & 0,8802 & 0,9543 & 0,9651 & 0,9641 & 0,9601 & 0,9394 & 0,9501 \\
Remove Stopwords   & 0,9824 & 0,9835 & 0,9671 & 0,9562 & 0,8692 & 0,8802 & 0,8681 & 0,9651 & 0,9579 & 0,9641 & 0,9603 & 0,9501 \\
Remove Numbers     & 0,9764 & 0,9835 & 0,9659 & 0,9671 & 0,8812 & 0,8802 & 0,9521 & 0,9651 & 0,9694 & 0,9641 & 0,9602 & 0,9603 \\
Stemming           & 0,9787 & 0,9835 & 0,9541 & 0,9671 & 0,8640 & 0,8812 & 0,9312 & 0,9651 & 0,9576 & 0,9694 & 0,9508 & 0,9603 \\
\bottomrule
\end{tabular*}

\end{table*}

\end{document}

相关内容