Why Does LaTeX Report an Underfull \hbox in a Table?
At a glance
- 1. Read the warning
An underfull hbox means TeX could not space a line naturally to fill its available width; badness 10000 is the maximum.
- 2. Find the paragraph
Use the line numbers in the log, then inspect nearby text and table cells, especially paragraph-style p columns.
- 3. Adjust the layout
Widen or shorten content, or use ragged-right alignment in narrow paragraph columns.
- 4. Recompile and check
Confirm the layout is acceptable; do not hide the warning unless you have a specific reason.
An “Underfull \hbox (badness 10000)” message is usually a warning, not a compilation error. It means TeX tried to make a line fill a specified width by stretching the spaces between words, but the result would be too loose. A badness of 10000 is TeX’s maximum reported badness.
A table made with tabular does not prevent this warning. TeX may be reporting a paragraph before or after the table, or a paragraph inside a p{...} column. A table editor or wizard can insert the table structure, but it cannot guarantee that all the surrounding text and cell contents will fit well.
What the warning refers to
TeX builds a paragraph from horizontal lines, or boxes. When it cannot find a line break that fits well, it may stretch the spaces between words to reach the line width. If the stretching is excessive, TeX reports an underfull box. The warning often includes source line numbers, but those numbers point to where TeX was processing—not necessarily to the exact word or table cell causing the poor spacing.
In a basic tabular column such as l, c, or r, each cell’s contents are not automatically wrapped like a paragraph. In contrast, a p{5cm} column creates a paragraph box of the specified width. TeX wraps and justifies text in that box, so a narrow column or awkwardly spaced content can trigger an underfull warning there.
How to find the source
- Look at the line numbers in the
.logfile or the output panel of your editor. - Inspect the paragraph around those lines, including text immediately before or after the table.
- Check any
p{...}columns and other boxes with fixed widths. Look for narrow columns, short fragments forced onto lines, manual line breaks, or fixed-width spacing commands such as\\hspaceor\\hskip. - Make a small layout change, recompile, and check whether the warning moves or disappears.
The warning may also refer to a paragraph elsewhere in the document. A table appearing near the reported line does not prove that the table caused it.
Example: make narrow columns ragged right
A narrow paragraph column is often easier to read when its text is ragged right rather than fully justified. The following complete example uses the array package to apply ragged-right alignment to both paragraph columns:
\\documentclass{article}
\\usepackage{array}
\\begin{document}
\\begin{tabular}{|>{\\raggedright\\arraybackslash}p{2.5cm}|>{\\raggedright\\arraybackslash}p{5cm}|}
\\hline
Item & Description \\\\
\\hline
A long item label & Text in a fixed-width paragraph column wraps naturally and is not stretched to justify every line. \\\\
\\hline
\\end{tabular}
\\end{document}
The p{...} column type sets a fixed column width and wraps its contents. The >{\\raggedright\\arraybackslash} modifier makes the cell text ragged right; \\arraybackslash restores \\ as the row-ending command. The array package provides this column modifier. If you need fully justified text, widening the column or shortening the content may be more appropriate.
Common mistakes
- Treating the warning as a fatal error. A document can produce a PDF with underfull-box warnings. Check the visual output as well as the log.
- Assuming the table wizard caused it. A wizard generally generates LaTeX source; it does not control line breaking in the rest of the document.
- Changing every cell alignment without checking. Ragged-right text can improve narrow columns, but it is not always the right layout for numeric or tabular data.
- Suppressing all warnings. Commands such as
\\hbadness=10000can hide useful diagnostics throughout the document. Prefer to fix the specific spacing issue, or accept a harmless warning if the result is intentional and looks good.
If the warning persists, reduce the document to a small example containing the nearby paragraph and table. That makes it easier to identify whether the cause is a cell, the surrounding text, or a forced line break.
References
- The TeXbook, Donald E. Knuth
- The LaTeX2e unofficial reference manual
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.