Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 9 down vote accepted

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
% \g@addto@macro{\centering}{\hbadness=\@M}
% \g@addto@macro{\raggedright}{\hbadness=\@M}
% \g@addto@macro{\raggedleft}{\hbadness=\@M}
% \g@addto@macro{\center}{\hbadness=\@M}
% \g@addto@macro{\flushleft}{\hbadness=\@M}
% \g@addto@macro{\flushright}{\hbadness=\@M}
\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}
share|improve this answer
3  
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.

share|improve this answer
    
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. –  Herbert 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
2  
it is explained in the documentation of ragged2e –  Herbert May 7 '11 at 11:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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