將產生的表格調整為寬度的問題

將產生的表格調整為寬度的問題

我已經在這裡查看了相當多的帖子,但一切似乎都打破了我的桌子,所以我想我應該發布我的問題並尋求幫助。我使用生成了一個表https://www.tablesgenerator.com

我在將表格調整為頁面寬度而不縮小文字時遇到問題:

\documentclass[acmsmall]{acmart}
 \usepackage{graphicx}
   \usepackage[table,xcdraw]{xcolor}
      \begin{table}[]
        \resizebox{\textwidth}{!}{%
        \begin{tabular}{lcccccccccccc}
        \hline
        \rowcolor[HTML]{EFEFEF} 
        \multicolumn{13}{c}{\cellcolor[HTML]{EFEFEF}\textbf{Title}} \\ \hline
        \textit{\textbf{Hashtag}} & \multicolumn{3}{c}
        {\textit{\textbf{Service1}}} & \multicolumn{3}{c}
        {\textit{\textbf{Service2}}} & \multicolumn{3}{c}
        {\textit{\textbf{Service3}}} & \multicolumn{3}{c}
        {\textit{\textbf{Service4}}} \\ \hline
        \rowcolor[HTML]{EFEFEF} 
          \textit{} & \textit{True} & \textit{False} & \textit{Accuracy} & 
          \textit{True} & \textit{False} & \textit{Accuracy} & \textit{True} & 
          \textit{False} & \textit{Accuracy} & \textit{True} & \textit{False} & 
          \textit{Accuracy} \\ \hline
          \textit{\#1} & n & n & n\% & x & x & x & n & n & n\% & n & 
           n & n\% \\ \hline
        \rowcolor[HTML]{EFEFEF} 
          \textit{\#2} & n & n & n\% & x & x & x & n & n & n\% & n & 
           n & n\% \\ \hline
          \textit{\#3} & n & n & n\% & x & x & x & n & n & n\% & n & 
           n & n\% \\ \hline
        \rowcolor[HTML]{EFEFEF} 
          \textit{\#4} & n & n & n\% & x & x & x & n& 100 & n\% & n
          & n & n\% \\ \hline
          \begin{tabular}[c]{@{}l@{}}\#5, \\ \#6, \\ \#7\end{tabular} & n & n & 
          n\% & n & n & n\% & n & n & n\% & n & n & n\% \\ \hline
      \end{tabular}%
      }
 \end{table}

答案1

\tabcolsep以下是使用較小或縮寫的列標題的另外兩種可能的解決方案:

在此輸入影像描述

\documentclass[acmsmall]{acmart}
\usepackage{graphicx}
\usepackage{colortbl}

\begin{document}

      \begin{table}
      \setlength{\tabcolsep}{4pt}
        \begin{tabular}{lcccccccccccc}
        \hline
        \rowcolor[HTML]{EFEFEF} 
        \multicolumn{13}{c}{\cellcolor[HTML]{EFEFEF}\textbf{Title}} \\ \hline
        \textit{\textbf{Hashtag}} & \multicolumn{3}{c}
        {\textit{\textbf{Service1}}} & \multicolumn{3}{c}
        {\textit{\textbf{Service2}}} & \multicolumn{3}{c}
        {\textit{\textbf{Service3}}} & \multicolumn{3}{c}
        {\textit{\textbf{Service4}}} \\ \hline
        \rowcolor[HTML]{EFEFEF} 
          \textit{} & \textit{True} & \textit{False} & \textit{Acc.} & 
          \textit{True} & \textit{False} & \textit{Acc.} & \textit{True} & 
          \textit{False} & \textit{Accuracy} & \textit{True} & \textit{False} & 
          \textit{Acc.} \\ \hline
          \textit{\#1} & n & n & n\% & x & x & x & n & n & n\% & n & 
           n & n\% \\ \hline
        \rowcolor[HTML]{EFEFEF} 
          \textit{\#2} & n & n & n\% & x & x & x & n & n & n\% & n & 
           n & n\% \\ \hline
          \textit{\#3} & n & n & n\% & x & x & x & n & n & n\% & n & 
           n & n\% \\ \hline
        \rowcolor[HTML]{EFEFEF} 
          \textit{\#4} & n & n & n\% & x & x & x & n& 100 & n\% & n
          & n & n\% \\ \hline
        \#5  &&&&&&&&&&&&\\                   
        \#6, & n & n & 
          n\% & n & n & n\% & n & n & n\% & n & n & n\% \\ 
        \#7  &&&&&&&&&&&&\\   
          \hline
          \end{tabular}
 \end{table}


      \begin{table}
        \begin{tabular}{lcccccccccccc}
        \hline
        \rowcolor[HTML]{EFEFEF} 
        \multicolumn{13}{c}{\cellcolor[HTML]{EFEFEF}\textbf{Title}} \\ \hline
        \textit{\textbf{Hashtag}} & \multicolumn{3}{c}
        {\textit{\textbf{Service1}}} & \multicolumn{3}{c}
        {\textit{\textbf{Service2}}} & \multicolumn{3}{c}
        {\textit{\textbf{Service3}}} & \multicolumn{3}{c}
        {\textit{\textbf{Service4}}} \\ \hline
        \rowcolor[HTML]{EFEFEF} 
          \textit{} & \textit{T} & \textit{F} & \textit{Acc.} & 
          \textit{T} & \textit{F} & \textit{Acc.} & \textit{T} & 
          \textit{F} & \textit{Acc.} & \textit{T} & \textit{F} & 
          \textit{Acc.} \\ \hline
          \textit{\#1} & n & n & n\% & x & x & x & n & n & n\% & n & 
           n & n\% \\ \hline
        \rowcolor[HTML]{EFEFEF} 
          \textit{\#2} & n & n & n\% & x & x & x & n & n & n\% & n & 
           n & n\% \\ \hline
          \textit{\#3} & n & n & n\% & x & x & x & n & n & n\% & n & 
           n & n\% \\ \hline
        \rowcolor[HTML]{EFEFEF} 
          \textit{\#4} & n & n & n\% & x & x & x & n& 100 & n\% & n
          & n & n\% \\ \hline
          \begin{tabular}[c]{@{}l@{}}\#5, \\ \#6, \\ \#7\end{tabular} & n & n & 
          n\% & n & n & n\% & n & n & n\% & n & n & n\% \\ \hline
          \multicolumn{13}{l}{T: True, F: False, Acc.: Accuracy}
      \end{tabular}%
 \end{table}

\end{document}

答案2

該表的列太多,無法適應正常大小的可用文字寬度,但\resizebox您可以手動選擇較小的字體大小,例如,而不是使用\small,這將為您提供更適合字體大小的字母形狀。

此外,您可以透過縮寫標題中的一些長單字來節省一些空間。

\PassOptionsToPackage{table,xcdraw}{xcolor}
\PassOptionsToPackage{showframe}{geometry}
\documentclass[acmsmall]{acmart}
 \usepackage{graphicx}


%   \usepackage[table,xcdraw]{xcolor}

\begin{document}

      \begin{table}[]
%        \resizebox{\textwidth}{!}{%
\small
        \begin{tabular}{lcccccccccccc}
        \hline
        \rowcolor[HTML]{EFEFEF} 
        \multicolumn{13}{c}{\cellcolor[HTML]{EFEFEF}\textbf{Title}} \\ \hline
        \textit{\textbf{Hashtag}} & \multicolumn{3}{c}
        {\textit{\textbf{Service1}}} & \multicolumn{3}{c}
        {\textit{\textbf{Service2}}} & \multicolumn{3}{c}
        {\textit{\textbf{Service3}}} & \multicolumn{3}{c}
        {\textit{\textbf{Service4}}} \\ \hline
        \rowcolor[HTML]{EFEFEF} 
          \textit{} & \textit{True} & \textit{False} & \textit{Acc.} & 
          \textit{True} & \textit{False} & \textit{Acc.} & \textit{True} & 
          \textit{False} & \textit{Accuracy} & \textit{True} & \textit{False} & 
          \textit{Acc.} \\ \hline
          \textit{\#1} & n & n & n\% & x & x & x & n & n & n\% & n & 
           n & n\% \\ \hline
        \rowcolor[HTML]{EFEFEF} 
          \textit{\#2} & n & n & n\% & x & x & x & n & n & n\% & n & 
           n & n\% \\ \hline
          \textit{\#3} & n & n & n\% & x & x & x & n & n & n\% & n & 
           n & n\% \\ \hline
        \rowcolor[HTML]{EFEFEF} 
          \textit{\#4} & n & n & n\% & x & x & x & n& 100 & n\% & n
          & n & n\% \\ \hline
        \#5  &&&&&&&&&&&&\\                   
        \#6, & n & n & 
          n\% & n & n & n\% & n & n & n\% & n & n & n\% \\ 
        \#7  &&&&&&&&&&&&\\   
          \hline
      \end{tabular}%
%      }
 \end{table}

 \end{document}

相關內容