[Tex/LaTex] Underfull \hbox (badness 10000) in longtable

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}|}
\caption{\label{tab:reading}AAA.}
\\ \hline
AAAAAAAAAA & AAAA BBBBBW & AAA \\ \hline
\end{longtable}
\end{document}

Best Answer

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}|}
\caption{\label{tab:reading}AAA.}
\\ \hline
AAAAAAAAAA & AAAA BBBBBW & AAA \\ \hline
\end{longtable}
\end{document}
Related Question