# ragged2e: “newcommands” option produces “underfull \hbox” warnings

The ragged2e package provides the commands \Centering, \RaggedRight and \RaggedLeft for setting ragged text while allowing hyphenation. The package offers a newcommands option that sets the standard LaTeX commands \centering, \raggedright and \raggedleft equal to their ragged2e counterparts. However, when using this option, I've stumbled upon two instances where LaTeX will produce Underfull \hbox (badness 10000) warnings:

• Creating a title with \maketitle:

\documentclass{article}

\usepackage[newcommands]{ragged2e}

\begin{document}

\author{Author}
\title{Title}
\maketitle

\end{document}

• Creating headers and footers with either the fancyhdr or the scrpage2 package:

\documentclass{article}

\usepackage[newcommands]{ragged2e}

\usepackage[english]{babel}
\usepackage{blindtext}

\usepackage{fancyhdr}
\pagestyle{fancy}

\begin{document}

\blinddocument

\end{document}


What causes these warnings, and what are proper ways to remove them?

EDIT: In response to Herbert's answer: I'm looking for a solution that keeps hyphenation while getting rid of warnings.

According to p. 4 of the ragged2e documentation (thanks to Herbert for encouraging me to RTFM), the ragged2e lengths which control \leftskip resp. \rightskip for \Centering & friends "must be set to a finite value, to make hyphenation possible". (By default, ragged2e uses a value of 0pt plus 2em instead of standard LaTeX's 0pt plus 1fil.) But finit glue in turn means that "underfull \hbox" warnings become possible. In practice, such warnings are likely to be issued for one-liner or two-liner paragraphs typeset with \Centering & friends in effect -- i.e., they will turn up in (but are not confined to) title pages and headers.

This is demonstrated in the following MWE, which typesets text within three center environments (which, because ragged2e's newcommands option is enabled, internally use \Centering). The first environment will produce an underfull \hbox with a badness of 10000, the second environment one with a badness of 4096. In the third environment, the sixth word is moved to the second line (instead of being hyphenated), and no warning is issued.

To remove all those "underfull \hbox" warnings, \hbadness may be set to a value of 10000 for \Centering & friends (again thanks to Herbert for the tip). Note that, if the newcommands option is enabled, one must add \hbadness=10000\relax (EDIT: or, even better, \hbadness=\@M) to the new definitions of, e.g., \centering as well as to the start of center environments.

\documentclass[12pt]{article}

\usepackage[newcommands]{ragged2e}

% Uncommenting the following lines will remove "underfull \hbox" warnings
\makeatletter
\makeatother

\begin{document}

\begin{center}
hyphenation
\end{center}

\begin{center}
hyphenation hyphenation hyphenation hyphenation hyphenation
hyphenation hyphenation hyphenation hyphenation
\end{center}

\begin{center}
hyphenation hyphenation hyphenation hyphenation hyphenation
hyphenation hyphenation hyphenation hyphenation hyphenation
\end{center}

\end{document}

• I think you can omit \relax if you use \@M instead of 10000. – mhp Sep 16 '11 at 7:44

With ragged2e you have \CenteringRightskip=0pt plus 2em, but LaTeX uses a value of 0pt plus 1fil. You can set \CenteringRightskip to this value and there will be no warning.

• Thanks for your answer. I suppose that \CenteringLeftSkip should also be corrected. Also, your suggestion will remove hyphenation from \Centering, and I'd like to keep hyphenation while getting rid of warnings (if possible). – lockstep May 7 '11 at 10:13
• @lockstep: {\hbadness=10000\maketitle} and read the documentation on page 4. – user2478 May 7 '11 at 10:29
• Okay, so plus 1fil will kill hyphenation. Also thanks for the idea to set \hbadness to 10000 locally. Still, it's treating the symptom, and I'd like to know the cause. – lockstep May 7 '11 at 10:43
• it is explained in the documentation of ragged2e – user2478 May 7 '11 at 11:37

I recommend loading the ragged2e package with the default originalcommands option instead of the newcommands option and only modify selected parts of the document (sections, captions, …) to be \RaggedRight. In multi-line text, "Underfull \hbox" warnings are rare. You usually should not use hyphenation on the title page and you should not need it in headers and footers anyway.

In my opinion, \RaggedRight is only useful for typesetting multi-line narrow text or multi-line text containing many non-breakable sequences such as URLs. This applies to captions, e.g. through the justification = RaggedRight option for package caption. In these cases, 0pt plus 2em might not be enough, so I'd increase this limit a bit, e.g. setting it to 0pt plus 3em.

Note that with @lockstep's answer, when uncommenting the lines between \makeatletter and \makeatother, every horizontal badness will be silenced. Since there might be valid reasons for these warnings, you should not silence them. With the original parameters, at least "Overfull \hbox" warnings will still be shown.