将多列设置为精确宽度

将多列设置为精确宽度

我是 Latex 表格的新手。我知道我可以用它做这件事,p{width}但当我尝试时,表格变得完全没有格式。我该怎么做才能让 Approach 列变小,以便表格可以适合页面?

谢谢。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\begin{document}
\begin{table}
\centering
\label{tabelaSemEval}
\begin{tabular}{llc|llc|llc} 
\hline
\multicolumn{3}{c}{ \textbf{Sub-task A}} & \multicolumn{3}{c}{\textbf{Sub-task B}} & \multicolumn{3}{c}{\textbf{Sub-task C }} \\
\multicolumn{1}{c|}{\textbf{Team Ranks}} & \multicolumn{1}{p{3cm}|}{\textbf{Approach}} & \multicolumn{1}{l|}{\textbf{F1 score} } & \multicolumn{1}{c|}{\textbf{Team Ranks}} & \multicolumn{1}{p{3cm}|}{\textbf{Approach}} & \multicolumn{1}{l|}{\textbf{F1 score} } & \multicolumn{1}{c|}{\textbf{Team Ranks}} & \multicolumn{1}{p{3cm}|}{\textbf{Approach}} & \multicolumn{1}{l}{\textbf{F1 score} } \\ 
\hline
NULI & BERT & 0.829 & jhan014 & MSOC & 0.755 & vradivchev anikolov & BERT+GloVe & 0.660 \\
vradivchev anikolov & BERT+GloVe & 0.815 & Amobee & CNN+token embedding & 0.739 & NLPR@SRPOL & ensemble of OpenAI,Finetune, LSTM, Transformer,SVM and Random Forest & 0.628 \\
UM-IU@LING & BERT & 0.814 & HHU & LSTM & 0.719 & Fermi & ELMo embeddings+ SVM & 0.626 \\
Embeddia & BERT & 0.808 & NULI & BERT & 0.716 & YNU-HPCC &  & 0.621 \\
MIDAS & CNN+LSTM+GRU and word embeddings & 0.807 & NIT Agartala & Logistic regression+ Linear SVC+SGD+PA & 0.708 & Embeddia & BOW+GloVe-LSTM+POS-LSTM & 0.613 \\
BNU-HKBU & BERT & 0.806 & UBC NLP & Emsemble of XGBoost+AdaBoost+logistic regression & 0.706 & NoOffense & - & 0.613 \\
SentiBERT & BERT & 0.804 & Pardeep & GRU & 0.700 & Amobee & CNN+token embedding & 0.591 \\
NLPR@SRPOL & ensemble of OpenAI,Finetune, LSTM,Transformer,SVM and Random Forest & 0.803 & MIDAS & model based on heuristics & 0.695 & orabia & - & 0.588 \\
YNUWB & CNN+word embeddings & 0.802 & NLPR@SRPOL & ensemble of OpenAI,Finetune, LSTM, Transformer,SVM and Random Forest & 0.692 & UBC NLP & Ensemble of logistic regression+AdaBoost+XGBoost & 0.586 \\
LTL-UDE & BERT & 0.802 & Vadym & - & 0.692 & na14 & - & 0.586
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

答案1

以下是我对如何重新构建表格的建议。由于表格太宽,无法放入边距(即使在横向页面上),我决定将三个子任务放在彼此之下,而不是彼此相邻。我还使用了包中的水平线booktabstabularx自动与文本宽度一样宽的表格包。

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{ragged2e}

\begin{document}

\begin{table}
\centering
\label{tabelaSemEval}
\begin{tabularx}{\linewidth}{@{\quad\quad}l>{\RaggedRight}Xc} 
\toprule
Team ranks & Approach & F1 score \\
\midrule
\multicolumn{3}{l}{\textit{Sub-task A}}\\
NULI & BERT & 0.829   \\
vradivchev anikolov & BERT+GloVe & 0.815 \\
UM-IU@LING & BERT & 0.814   \\
Embeddia & BERT & 0.808  \\
MIDAS & CNN+LSTM+GRU and word embeddings & 0.807 \\
BNU-HKBU & BERT & 0.806  \\
SentiBERT & BERT & 0.804 \\
NLPR@SRPOL & ensemble of OpenAI,Finetune, LSTM,Transformer,SVM and Random Forest & 0.803  \\
YNUWB & CNN+word embeddings & 0.802 \\
LTL-UDE & BERT & 0.802  \\
\midrule
\multicolumn{3}{l}{\textit{Sub-task B}}\\
jhan014 & MSOC & 0.755 \\
Amobee & CNN+token embedding & 0.739 \\
HHU & LSTM & 0.719\\
NULI & BERT & 0.716 \\
NIT Agartala & Logistic regression+ Linear SVC+SGD+PA & 0.708 \\
UBC NLP & Emsemble of XGBoost+AdaBoost+logistic regression & 0.706 \\
Pardeep & GRU & 0.700 \\
MIDAS & model based on heuristics & 0.695 \\
NLPR@SRPOL & ensemble of OpenAI,Finetune, LSTM, Transformer,SVM and Random Forest & 0.692\\
Vadym & - & 0.692 \\
\midrule
\multicolumn{3}{l}{\textit{Sub-task C}}\\
vradivchev anikolov & BERT+GloVe & 0.660\\
NLPR@SRPOL & ensemble of OpenAI,Finetune, LSTM, Transformer,SVM and Random Forest & 0.628 \\
Fermi & ELMo embeddings+ SVM & 0.626 \\
YNU-HPCC &  & 0.621 \\
Embeddia & BOW+GloVe-LSTM+POS-LSTM & 0.613 \\
NoOffense & - & 0.613 \\
Amobee & CNN+token embedding & 0.591 \\
orabia & - & 0.588 \\
UBC NLP & Ensemble of logistic regression+AdaBoost+XGBoost & 0.586 \\
na14 & - & 0.586 \\
\bottomrule
\end{tabularx}
\end{table}

\end{document}

答案2

另一种可能性:横向格式的表格,调整边距、字体大小和列之间的分隔空间。我删除了所有垂直规则,用更合适的尾号替换了连字符,并在符号周围添加了空格+,以便更容易换行:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{ragged2e}
\usepackage[margin=2cm]{geometry}
\usepackage{lscape}
\usepackage{tabularx, booktabs, makecell}
\renewcommand{\theadfont}{\bfseries}

\begin{document}

\begin{landscape}
\setlength{\tabcolsep}{4pt}
\footnotesize
\begin{table}
\centering
\label{tabelaSemEval}
    \begin{tabularx}{\linewidth}{*{2}{l>{\RaggedRight}X@{}c}l>{\RaggedRight}X@{}c}
    \toprule
    \multicolumn{3}{c}{\textbf{Sub-task A}} & \multicolumn{3}{c}{\textbf{Sub-task B}} & \multicolumn{3}{c}{\textbf{Sub-task C }} \\[1ex]
    \thead[l]{Team Ranks} &\thead[l]{Approach}& \thead{F1 score\,}& \thead[l]{Team Ranks} &\thead[l]{Approach}& \thead{F1 score\,} & \thead[l]{Team Ranks} &\thead[lc]{Approach}& \thead{F1 score\,}\\[1ex]
    \cmidrule(lr){1-3}\cmidrule(lr){4-6}\cmidrule(lr){7-9}
    \addlinespace[2ex]
    NULI & BERT & 0.829 & jhan014 & MSOC & 0.755 & vradivchev anikolov & BERT + GloVe & 0.660 \\
    vradivchev anikolov & BERT + GloVe & 0.815 & Amobee & CNN + token embedding & 0.739 & NLPR@SRPOL & ensemble of OpenAI,Finetune, LSTM, Transformer,SVM and Random Forest & 0.628 \\
    UM-IU@LING & BERT & 0.814 & HHU & LSTM & 0.719 & Fermi & ELMo embeddings + SVM & 0.626 \\
    Embeddia & BERT & 0.808 & NULI & BERT & 0.716 & YNU-HPCC & & 0.621 \\
    MIDAS & CNN + LSTM + GRU and word embeddings & 0.807 & NIT Agartala & Logistic regression + Linear SVC + SGD + PA & 0.708 & Embeddia & BOW + GloVe-LSTM + POS-LSTM & 0.613 \\
    BNU-HKBU & BERT & 0.806 & UBC NLP & Ensemble of XGBoost + AdaBoost + logistic regression & 0.706 & NoOffense & -- & 0.613 \\
    SentiBERT & BERT & 0.804 & Pardeep & GRU & 0.700 & Amobee & CNN + token embedding & 0.591 \\
    NLPR@SRPOL & ensemble of OpenAI, Finetune, LSTM, Transformer, SVM and Random Forest & 0.803 & MIDAS & model based on heuristics & 0.695 & orabia & -- & 0.588 \\
    YNUWB & CNN + word embeddings & 0.802 & NLPR@SRPOL & ensemble of OpenAI, Finetune, LSTM, Transformer, SVM and Random Forest & 0.692 & UBC NLP & Ensemble of logistic regression + AdaBoost + XGBoost & 0.586 \\
    LTL-UDE & BERT & 0.802 & Vadym & -- & 0.692 & na14 & -- & 0.586 \\
    \addlinespace[2ex]
    \bottomrule
    \end{tabularx}
\end{table}
\end{landscape}

\end{document}

在此处输入图片描述

相关内容