3

I have the following MWE LaTeX code:

\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}

When I compile it I get a number of Underfull \hbox warnings:

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

I have no idea what's causing them. Could anyone please advise?

  • 1
    they are not errors but warnings telling you that justifying text in narrow columns is hard and tex is having to over-stretch the inter word space. Often it is better to set table columns ragged right – David Carlisle May 6 '18 at 10:43
  • Yes, fixed that thanks. I tried \raggedright in the column-spec but I'm still getting the warnings. – K G May 6 '18 at 10:55
5

I propose this code, defining a new column type, based on X, which enters and leaves an itemize environment. I added loading of caption to have a decent spacing between caption and table, ragged2e and 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} 

enter image description here

  • Thanks. What does @minipagetrue do? – K G May 6 '18 at 11:39
  • An itemize environment at the beginning of a minipage inserts no vertical space. I stole the code somewhere on this site :o) – Bernard May 6 '18 at 11:56
  • @Mico: You're right. I just had in mind the cells contents in the first column were one-lined, so I didn't care about this point. I'll make some tests and post the modifications. However, note columns 2 and 3 are justified if possible since I use \RaggedRight. – Bernard May 6 '18 at 16:36
  • 1
    @Mico: Done, mylord! ;o) – Bernard May 6 '18 at 17:17
4

Here's an adaptation of your code which (a) uses ragged-right by default in columns of type X and (b) employs an itemize-like list environment that maximizes the available space.

enter image description here

\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}
  • Thanks. Both yours and @Bernard's answers are correct but since I can only choose one I chose his as I find it more elegant. – K G May 6 '18 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.