如何根据内容自动调整表格?

如何根据内容自动调整表格?

我检查了整个网络,但我试图根据内容自动调整表格中的列。从下面:

在此处输入图片描述

到:

在此处输入图片描述

代码如下:

\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{booktabs, tabularx}
\usepackage{textcomp}
\usepackage{xcolor}
\usepackage{multirow}
\usepackage[utf8]{inputenc}

\begin{document}

\maketitle

\section{Introduction}
\begin{table}[htbp]
\caption{Query list for the word 'wooden' at the start of the game and 
 during the game}
\begin{tabular}{|c|c|c|}
\hline
\textbf{Generation No.}&{\textbf{The noun which is being queried}}& {\textbf{Nearest Neighbor using analogy function}} \\
\hline
0  (Start of the game) & \multirow{2}{*}{wooden} & ['get_VBP', 'reply_VBP', 'repaint_VB', 
'publicity_NN', 'of_IN', 'adorn_VB', 'hands_VBZ', 'stiffen_VB', 'has_VBZ', 
'before_IN', 'solve_VB', 'west_JJS', 'are_VBP', 'hoist_VB', 'decorate_VB', 
'he_PRP', 'you_PRP', 'want_VBP', 'to_TO', 'bad_JJ', 'erect_VB', 'once_RB', 
'go_VB', 'buckle_VB', 'read_VBN', 'sheet_NN', 'it_PRP', 'carrying_VBG', 
'have_VBP', 'pound_VB']\\ \cline{2}
\hline

100 & & ['reply_VBP', 'stiffen_VB', 'before_IN', 'i_PRP', 'adorn_VB', 
'repaint_VB', 'any_DT', 'erect_VB', 'lift_VB', 'in_IN', 'publicity_NN', 
'decorate_VB', 'paper_NN', 'or_CC', 'he_PRP', 'drape_VB', 'once_RB', 
'fbi_NNP', 'go_VB', 'weld_VB', 'buckle_VB', 'come_VB', 'west_JJS', 
'are_VBP', 
'hoist_VB', 'fasten_VB', 'you_PRP', 'to_TO', 'bad_JJ', 'pound_VB'] \\
\hline
\end{tabular}
\label{tab1}
\end{table}

\end{document}

答案1

  • 对于表格环境,我建议使用tabularx环境。它允许您将文本分成多行
  • 使用的字体没有粗体字形
  • 表格可以位于一列中,并放置在插入位置附近:

在此处输入图片描述

或跨越下一页顶部的两列插入

在此处输入图片描述

  • 为了在单元格中文本周围留出更多垂直空间,使用了\makegapedcells包中的宏makecell

    \documentclass[conference]{IEEEtran}
    \IEEEoverridecommandlockouts
    \usepackage{booktabs, makecell, multirow, tabularx}
    \newcolumntype{L}{>{\raggedright\arraybackslash}X}
    \usepackage{textcomp}
    \usepackage{xcolor}
    \usepackage[utf8]{inputenc}
    
    \usepackage{lipsum}
    
    \begin{document}
        \lipsum[1]
    \begin{table}[htbp]
    \caption{Query list for the word 'wooden' at the start of the game and
     during the game}
        \setlength{\tabcolsep}{2pt}
        \setcellgapes{3pt}\makegapedcells
    \begin{tabularx}{\linewidth}{|*{2}{>{\hsize=0.21\hsize}L|}
                                       >{\hsize=0.58\hsize}L|}
        \hline
    Generation No.
        &   The noun which is being queried
            &   Nearest Neighbor using analogy function        \\
        \hline
    0  (Start of the game)
        &   wooden
            &   ['get\_VBP', 'reply\_VBP', 'repaint\_VB',
                 'publicity\_NN', 'of\_IN', 'adorn\_VB', 'hands\_VBZ', 'stiffen\_VB', 'has\_VBZ',
                 'before\_IN', 'solve\_VB', 'west\_JJS', 'are\_VBP', 'hoist\_VB', 'decorate\_VB',
                 'he\_PRP', 'you\_PRP', 'want\_VBP', 'to\_TO', 'bad\_JJ', 'erect\_VB', 'once\_RB',
                 'go\_VB', 'buckle\_VB', 'read\_VBN', 'sheet\_NN', 'it\_PRP', 'carrying\_VBG',
                 'have\_VBP', 'pound\_VB']                                \\
        \cline{1-3}
    100 &   &   ['reply\_VBP', 'stiffen\_VB', 'before\_IN', 'i\_PRP', 'adorn\_VB',
                 'repaint\_VB', 'any\_DT', 'erect\_VB', 'lift\_VB', 'in\_IN', 'publicity\_NN',
                 'decorate\_VB', 'paper\_NN', 'or\_CC', 'he\_PRP', 'drape\_VB', 'once\_RB',
                 'fbi\_NNP', 'go\_VB', 'weld\_VB', 'buckle\_VB', 'come\_VB', 'west\_JJS',
                 'are\_VBP', 'hoist\_VB', 'fasten\_VB', 'you\_PRP', 'to\_TO', 'bad\_JJ',
                 'pound\_VB']                                            \\
        \hline
    \end{tabularx}
    \label{tab1}
    \end{table}
        \lipsum[2]
    \begin{table*}[htbp]
    \caption{Query list for the word 'wooden' at the start of the game and
     during the game}
        \setcellgapes{3pt}\makegapedcells
    \begin{tabularx}{\linewidth}{|*{2}{>{\hsize=0.15\hsize}L|}
                                       >{\hsize=0.70\hsize}L|}
        \hline
    Generation No.
        &   The noun which is being queried
            &   Nearest Neighbor using analogy function        \\
        \hline
    0  (Start of the game)
        &   wooden
            &   ['get\_VBP', 'reply\_VBP', 'repaint\_VB',
                 'publicity\_NN', 'of\_IN', 'adorn\_VB', 'hands\_VBZ', 'stiffen\_VB', 'has\_VBZ',
                 'before\_IN', 'solve\_VB', 'west\_JJS', 'are\_VBP', 'hoist\_VB', 'decorate\_VB',
                 'he\_PRP', 'you\_PRP', 'want\_VBP', 'to\_TO', 'bad\_JJ', 'erect\_VB', 'once\_RB',
                 'go\_VB', 'buckle\_VB', 'read\_VBN', 'sheet\_NN', 'it\_PRP', 'carrying\_VBG',
                 'have\_VBP', 'pound\_VB']                                \\
        \cline{1-3}
    100 &   &   ['reply\_VBP', 'stiffen\_VB', 'before\_IN', 'i\_PRP', 'adorn\_VB',
                 'repaint\_VB', 'any\_DT', 'erect\_VB', 'lift\_VB', 'in\_IN', 
    

相关内容