在 tabularx 环境中,minipage 导致 \hbox 未满

在 tabularx 环境中,minipage 导致 \hbox 未满

我有以下 MWE LaTeX 代码:

\documentclass{article}

\usepackage{tabularx}
\usepackage{booktabs}

\newenvironment{tablepage}[1][\linewidth]{%
    \begin{minipage}[t]{#1}
        \begin{itemize}
}{\end{itemize}\end{minipage}}

\begin{document}

\begin{table}[htbp]
    \small
    \caption[Smart city goals, challenges and domains.]{Smart city goals, challenges and domains.}
    \label{tab:smart_domains}
    \begin{tabularx}{\textwidth}{XXX}
        \toprule
        \textbf{Goals} & \textbf{Challenges} & \textbf{Domains} \\
        \toprule
        Economic growth &
            \begin{tablepage}
                \item Controlled transition of the labour market due to automation
            \end{tablepage} &
            \begin{tablepage}
                \item Smart Mobility
            \end{tablepage} \\
        \midrule
        Quality of life &
            \begin{tablepage}
                \item Winning the war on talent between metropolitan areas
            \end{tablepage} &
            \begin{tablepage}
                \item Smart Safety
            \end{tablepage} \\
        \midrule
        Reduced ecological footprint &
            \begin{tablepage}
                \item Social cohesion, inclusiveness, solidarity
                \item Secure digital environment, privacy
                \item Resilience
            \end{tablepage} &
            \begin{tablepage}
                \item Smart Energy, Water \& Waste
                \item Smart Buildings \& Living
                \item Smart Health
                \item Smart Education
                \item Smart Finance
                \item Smart Tourism \& Leisure
                \item Smart Retail \& Logistics
                \item Smart Manufacturing \& Construction
                \item Smart Government
            \end{tablepage} \\
        \bottomrule
    \end{tabularx}
\end{table}

\end{document}

当我编译它时,我收到许多Underfull \hbox警告:

Underfull \hbox (badness 6542) in paragraph
Underfull \hbox (badness 3039) in paragraph
Underfull \hbox (badness 10000) in paragraph
Underfull \hbox (badness 10000) in paragraph
Underfull \hbox (badness 1038) in paragraph

我不知道是什么原因造成的。有人能给出建议吗?

答案1

我建议使用以下代码,基于 定义一种新的列类型,X该列类型进入和离开 itemize 环境。我添加了 的加载, caption以便在标题和表格之间留出合适的间距,ragged2e并且enumitem

\documentclass{article}

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

\usepackage{enumitem}
    \makeatletter
    \newcommand*{\compress}{\@minipagetrue}
    \makeatother

    \newcolumntype{I}{>{\compress\itemize}X <{\enditemize}}

\begin{document}

\begin{table}[htbp]
    \small
    \caption[Smart city goals, challenges and domains.]{Smart city goals, challenges and domains.}
    \label{tab:smart_domains}
    \setlist[itemize]{wide=0pt, nosep, leftmargin= *, after=\vspace{-\baselineskip}}
    \begin{tabularx}{\textwidth}{>{\RaggedRight\arraybackslash}X *{2}{>{\RaggedRight\arraybackslash}I}}
        \toprule
 \multicolumn{1}{l}{\bfseries Goals} & \multicolumn{1}{l}{\bfseries Challenges} & \multicolumn{1}{l}{\bfseries Domains} \\
 \toprule
        Economic growth &
                \item Controlled transition of the labour market due to automation
                 & \item Smart Mobility \\
        \midrule
        Quality of life & \item Winning the war on talent between metropolitan areas & \item Smart Safety \\
        \midrule
        Reduced ecological footprint &
                \item Social cohesion, inclusiveness, solidarity
                \item Secure digital environment, privacy
                \item Resilience &
                \item Smart Energy, Water \& Waste
                \item Smart Buildings \& Living
                \item Smart Health
                \item Smart Education
                \item Smart Finance
                \item Smart Tourism \& Leisure
                \item Smart Retail \& Logistics
                \item Smart Manufacturing \& Construction
                \item Smart Government \\
        \bottomrule
    \end{tabularx}
\end{table}

\end{document} 

在此处输入图片描述

答案2

这是您的代码的改编,其(a)在类型的列中默认使用 ragged-rightX以及(b)采用类似于 itemize 的列表环境来最大化可用空间。

在此处输入图片描述

\documentclass{article}

\usepackage{tabularx,booktabs,ragged2e}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X} % modified 'X' col. type

\usepackage{enumitem}
\newlist{mylist}{itemize}{1}
\setlist[mylist]{label=\textbullet,wide=0pt,leftmargin=*}

\newenvironment{tablepage}[1][\linewidth]{%
    \begin{minipage}[t]{#1}\begin{mylist}}{%
    \end{mylist}\end{minipage}}

\begin{document}

\begin{table}[htbp]
\small
\caption[Smart city goals, challenges and domains.]%
        {Smart city goals, challenges and domains.}
\label{tab:smart_domains}

\begin{tabularx}{\textwidth}{@{}LLL@{}}
\toprule
\textbf{Goals} & \textbf{Challenges} & \textbf{Domains} \\
\midrule
Economic growth &
\begin{tablepage}
      \item Controlled transition of the labour market due to automation
\end{tablepage} &
\begin{tablepage}
      \item Smart Mobility
\end{tablepage} \\
\midrule
Quality of life &
\begin{tablepage}
      \item Winning the war on talent between metropolitan areas
\end{tablepage} &
\begin{tablepage}
      \item Smart Safety
\end{tablepage} \\
\midrule
Reduced ecological footprint &
\begin{tablepage}
      \item Social cohesion, inclusiveness, solidarity
      \item Secure digital environment, privacy
      \item Resilience
\end{tablepage} &
\begin{tablepage}
      \item Smart Energy, Water~\& Waste
      \item Smart Buildings~\& Living
      \item Smart Health
      \item Smart Education
      \item Smart Finance
      \item Smart Tourism~\& Leisure
      \item Smart Retail~\& Logistics
      \item Smart Manufacturing~\& Construction
      \item Smart Government
\end{tablepage} \\
\bottomrule
\end{tabularx}
\end{table}

\end{document}

相关内容