# Underfull \hbox (badness 10000) in longtable

I have 1 badbox: Underfull \hbox (badness 10000) in paragraph. I know where the badbox is from. If you change "BBBBBW" in the code to "BBBBB", the badbox will be gone. So maybe because LaTeX does not know how to go to a newline correctly and beautifully. Is there way to solve this?

\documentclass[a4paper,man,natbib]{apa6}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{longtable}

\title{AA}
\shorttitle{AA}
\author{AA}
\affiliation{AA}
\abstract{AA}

\begin{document}
\maketitle

\centering
\begin{longtable}{|p{.25\textwidth}|p{.20\textwidth}|p{.47\textwidth}|}
\\ \hline
AAAAAAAAAA & AAAA BBBBBW & AAA \\ \hline
\end{longtable}
\end{document}

• Add \raggedright at the beginning of the column data (as in AAAAAAAAAA & \raggedright AAAA BBBBBW & AAA \\ \hline ). Essentially, because a single word only fits on the line, it cannot space the words for full alignment. Thus, the underfull box. Making the right margin ragged eliminates the imperative to fully align the column. – Steven B. Segletes Oct 28 '15 at 1:17
• Hi @StevenB.Segletes Is there a smart way? because I have a really big table, so I got over 50 badbox. And I don't know which cell is. Thanks – Hongbo Miao Oct 28 '15 at 1:52

In a comment to the OP, I identified the source of the underfull \hbox as a problem in trying to enforce full alignment on a narrow column where only one word fit within the column width. In that case, full alignment could not be achieved and an underfull box resulted. The proposed solution was to define the cell as \raggedright.

The OP then asked if there was a way to automate this solution for the longtable, as it was large, with many such box issues. The solution I propose here is to define a new column type (I call it P) which invokes \raggedright and other stuff necessary to handle all columns. (I coincidentally grabbed the column type definition from this unrelated question: Making LaTeX tabular environment behave well under copy/paste)

\documentclass[a4paper,man,natbib]{apa6}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{longtable}

\usepackage{array}
\newcolumntype{P}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}

\title{AA}
\shorttitle{AA}
\author{AA}
\affiliation{AA}
\abstract{AA}

\begin{document}
\maketitle

\begin{longtable}{|P{.25\textwidth}|P{.20\textwidth}|P{.47\textwidth}|}