如何修復單字混合的表格

如何修復單字混合的表格

我有一張大約有 10 列的表,並且列標題相交

如何在不更改表格設計的情況下分隔列(需要在此設計中)

這是腳本

\documentclass[computers,article,submit,moreauthors,pdftex]{Definitions/mdpi} 

% MDPI internal commands - do not modify
\firstpage{1} 
\makeatletter 
\setcounter{page}{\@firstpage} 
\makeatother
\pubvolume{1}
\issuenum{1}
\articlenumber{0}
\pubyear{2023}
\copyrightyear{2023}
\datereceived{ } 
\daterevised{ } % Comment out if no revised date
\dateaccepted{ } 
\datepublished{ } 
\hreflink{https://doi.org/} % If needed use \linebreak

\Title{Test}

\begin{document}
\section{Background}
This the table \ref{table_FinalDataset}


\begin{table}[H] 
\caption{xxxxxxxxxxxxxxxxxxxxx.}
\label{table_FinalDataset}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{tabularx}{\textwidth}{CCCCCCCCCCC}
\toprule
\multirow{2}{*}{\textbf{Report ID}}
& \multicolumn{5}{c}{\textbf{Features}}
& \multicolumn{5}{c}{\textbf{Labels}} \\ 
\cline{2-11}
& \textbf{C0004482} & \textbf{C0224473} & \textbf{C0719349}
& \textbf{C0230431} & \textbf{C0420607} & \textbf{295}
& \textbf{300}  & \textbf{303}  & \textbf{540}
& \textbf{560}\\
\midrule
            1012    &6  &0  &0  &4  &2  &0  &1  &1  &0  &0\\            
            1013    &0  &2  &2  &8  &0  &1  &1  &0  &0  &1  \\          
            1014    &0  &0  &4  &4  &9  &1  &0  &1  &0  &0  \\ 
            
\bottomrule
\end{tabularx}
\end{table}
\end{document}

答案1

您的問題是“功能”是長列條目,並且X列類型(這就是您定義C的)使所有列具有相同的寬度。如果您切換到c列,那麼它們對於其內容來說將足夠寬,但表格(很可能)對於文字區域來說太寬。 “你該如何適應文字?”在轉向 TeX 來實現「如何」之前,您需要回答這個問題。

一種選擇是旋轉要素列標籤。這通常不被看好,所以如果你想要的話我會讓你查一下。第二種選擇是在交替行中交錯排列要素列標籤。第三個選項(我的偏好)是將「功能」和「標籤」部分分成單獨的表格。

選項2:
選項2輸出

選項 3:
選項3輸出

\documentclass{article}

\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}
\section{Background}
This the table \ref{table_FinalDataset}

% option 2
\begin{table}
\caption{xxxxxxxxxxxxxxxxxxxxx.}
\label{table_FinalDataset}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{tabularx}{\textwidth}{cCCCCCccccc}
\toprule
\textbf{Report}
& \multicolumn{5}{c}{\textbf{Features}}
& \multicolumn{5}{c}{\textbf{Labels}} \\ 
\cmidrule(lr){2-6}\cmidrule(l){7-11}
\textbf{ID} &  & \makebox[0pt]{\textbf{C0224473}} & 
& \makebox[0pt]{\textbf{C0230431}} &  & \textbf{295}
& \textbf{300}  & \textbf{303}  & \textbf{540}
& \textbf{560}\\
& \makebox[0pt]{\textbf{C0004482}} & & \makebox[0pt]{\textbf{C0719349}} && \makebox[0pt]{\textbf{C0420607}} \\
\midrule
            1012    &6  &0  &0  &4  &2  &0  &1  &1  &0  &0\\            
            1013    &0  &2  &2  &8  &0  &1  &1  &0  &0  &1  \\          
            1014    &0  &0  &4  &4  &9  &1  &0  &1  &0  &0  \\ 
            
\bottomrule
\end{tabularx}
\end{table}

\clearpage

% option 3a
\begin{table}[h]\small
\caption{Features by Report ID.}
\label{table_FinalDataset_features}
\begin{tabular*}{\textwidth}{cccccc}
\toprule
\textbf{Report ID}
& \textbf{C0004482} & \textbf{C0224473} & \textbf{C0719349}
& \textbf{C0230431} & \textbf{C0420607} \\
\midrule
            1012    &6  &0  &0  &4  &2\\            
            1013    &0  &2  &2  &8  &0\\          
            1014    &0  &0  &4  &4  &9\\ 
\bottomrule
\end{tabular*}
\end{table}

% option 3b
\begin{table}[h]\centering
\caption{Labels by Report ID.}
\label{table_FinalDataset_labels}
\begin{tabular}{cccccc}
\toprule
\textbf{Report ID} & \textbf{295}
& \textbf{300}  & \textbf{303}  & \textbf{540}
& \textbf{560}\\
\midrule
            1012    &0  &1  &1  &0  &0\\            
            1013    &1  &1  &0  &0  &1  \\          
            1014    &1  &0  &1  &0  &0  \\ 
\bottomrule
\end{tabular}
\end{table}
\end{document}

相關內容