IEEEtran:如何对齐表格中的文本

IEEEtran:如何对齐表格中的文本

我在IEEEtran.cls班上工作。我需要一种方法来格式化我的表格,其中包含少量列,但某些列中包含较长的文本。

梅威瑟:

\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts

\usepackage{booktabs}
\usepackage{lipsum}  
\usepackage{tabularx,ragged2e}
\usepackage{lipsum}

\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
    T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
\begin{document}

\title{Conference Paper Title (IEEEtran)}

\maketitle

\begin{abstract}
This document is a model and instructions for \LaTeX.
This and the IEEEtran.cls ...
\end{abstract}

\begin{IEEEkeywords}
keyword1, keyword2
\end{IEEEkeywords}

\section{Introduction}

\lipsum[1]

\begin{table}[!hbtp]
    \caption{datasets' characteristics}
    \label{tab:datasets}
    \centering
    \setlength\tabcolsep{0pt}  %%%  optional
    \begin{tabularx}{\linewidth}{@{\extracolsep{\fill}} lcc}
    \toprule
                            & Dataset1  &  Dataset2 \\
    \midrule
    Time span of data collection  & 1 month (July 2010) & 5 years (February 2007 - April 2012   \\
    Number of participants  &    235   &   173 (54 user annotated)  \\
    \bottomrule     
    \end{tabularx}
\end{table}

\end{document}

输出:

在此处输入图片描述

答案1

  • tabularx表应至少具有一个X或从其派生的列类型
  • 在你的情况下,定义新的列类型是明智的,例如
    \newcolumntype{C}{>{\Centering}X}
    \newcolumntype{L}{>{\RaggedRight}X}
    \newcolumntype{R}{>{\RaggedLeft}X}

在单元格中启用自动文本拆分,并分别将其居中、左对齐和右对齐:

  • 考虑到上述情况,一个可能的解决方案是:
\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts

\usepackage{lipsum}

\usepackage{ragged2e}
\usepackage{booktabs, tabularx}
    \newcolumntype{C}{>{\Centering}X}
    \newcolumntype{L}{>{\RaggedRight}X}
    \newcolumntype{R}{>{\RaggedLeft}X}


\begin{document}
\lipsum[1]

    \begin{table}[!hbtp]
\caption{datasets' characteristics}
\label{tab:datasets}
    \centering
\begin{tabularx}{\linewidth}{@{} LcC @{}}
    \toprule
    & Dataset1  &  Dataset2                     \\
    \midrule
Time span of data collection    
    & 1 month (July 2010) 
        & 5 years (February 2007 - April 2012   \\
    \addlinespace
Number of participants      
    & 235   
        &   173 (54 user annotated)             \\
    \bottomrule
\end{tabularx}
    \end{table}
\end{document}

在此处输入图片描述

答案2

\documentclass[conference]{IEEEtran}
\usepackage{lipsum}
\usepackage{booktabs}
\usepackage{tabularx}
\begin{document}
\lipsum

\begin{table}
\caption{datasets' characteristics}
\label{tab:datasets}
\centering
\begin{tabularx}{\linewidth}{XXX}
\toprule
                             & Dataset1            & Dataset2                            \\
\midrule
Time span of data collection & 1 month (July 2010) & 5 years (February 2007 - April 2012) \\
Number of participants       & 235                 & 173 (54 user annotated)             \\
\bottomrule
\end{tabularx}
\end{table}

\end{document}

在此处输入图片描述

我建议你使用tabularray

\documentclass[conference]{IEEEtran}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{tabularray}
\begin{document}
\lipsum
\begin{table}
\caption{datasets' characteristics}
\label{tab:datasets}
\centering
\begin{tblr}
{
colspec        = {X[c,m]Q[c,m]Q[c,m]},
row{even[2-Z]} = {bg=gray9!50},
row{1}         = {font=\bfseries},
hline{1,Z}     = {wd=.08em},
hline{2}       = {wd=.05em},
}
                             & Dataset1               & Dataset2                                 \\
Time span of data collection & {1 month\\(July 2010)} & {5 years\\(February 2007\\- April 2012)} \\
Number of participants       & 235                    & {173\\(54 user annotated)}               \\
\end{tblr}
\end{table}
\end{document}

在此处输入图片描述

相关内容