首页 > 解决方案 > 表中未满 \hbox (badness 10000)

问题描述

我有下一张桌子,但它显示了标题的警告。

            \begin{table}[!hbt]
            \centering
            \caption{Learning Types}
            \begin{tabular}{| p{0.14\textwidth} | p{0.42\textwidth} | p{0.34\textwidth} |}
                
                \hline Supervised Learning & The data you feed to the algorithm is labeled.        
                                             It is often used for classification and regression  &  \Centerstack{\\k-Nearest Neighbors\\Linear Regression\\
                                                                                                           Logistic Regression\\Support Vector Machines (SVMs)\\
                                                                                                           Decision Trees and Random Forests\\Neural networks\\} \tabularnewline
                \hline Unsupervised Learning & hh & hh \tabularnewline
                \hline Semi-supervised Learning & hh & hh \tabularnewline
                \hline Reinforcement Learning & hh & hh \tabularnewline \hline
            \end{tabular}
            \end{table}

我搜索过,有人说是因为 \\(现在是 \tabularnewline),但我不知道如何使警告消失。

标签: latex

解决方案


p{<len>}规范试图证明任何多行内容的合理性,将其拉伸,使其与列边界左对齐和右对齐(最后一行除外)。在您的情况下,无法伸展Supervised以完全适合0.14\textwidthin ,从而导致“未满\hbox”警告。

由于该列非常窄,因此最好使用\makecell(来自makecellpackage)强制一些对齐/间距。下面我也使用了booktabsandtabularx来提高视觉吸引力。

在此处输入图像描述

\documentclass{article}

\usepackage{booktabs,makecell,tabularx}

\begin{document}

\begin{table}
  \centering
  \caption{Learning Types}
  \begin{tabularx}{\linewidth}{ l X l }
    \toprule
    \thead{Type} & \thead{Description} & \thead{Example(s)} \\
    \midrule
    \makecell[lt]{Supervised \\ Learning} & 
      The data you feed to the algorithm is labeled.
      It is often used for classification and regression &
      \makecell[lt]{%
        $k$-Nearest Neighbors             \\
        Linear Regression                 \\
        Logistic Regression               \\
        Support Vector Machines (SVMs)    \\
        Decision Trees and Random Forests \\
        Neural networks%
      } \\
    \addlinespace[10pt]
    \makecell[lt]{Unsupervised \\ Learning} & Description & Example(s) \\
    \addlinespace[10pt]
    \makecell[lt]{Semi-supervised \\ Learning} & Description & Example(s) \\
    \addlinespace[10pt]
    \makecell[lt]{Reinforcement \\ Learning} & Description & Example(s) \\
    \bottomrule
  \end{tabularx}
\end{table}

\end{document}

推荐阅读