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.

I created an environment for a thesis about a framework, which formats documentation of some methods. The method(s) are at the top with one line per method, set with \lstinline from the listings package.

Whenever a method signature is too long for one line and it is broken, I get "Underfull \hbox (badness 10000)". I searched for a while, but the recommendations for dealing with that warning are not suitable in this case:

  • There are no manual line breaks, that cause the underful \hbox, it occurs only on automatic break.

  • adding hyphenation is not suitable for program code, same for changing wording

Here is an example document with my environment:




\begin{methods}{Matrix<T> submatrix()}

    This method's signature is short, it does not break and no underful hbox
    warning is issued.


\begin{methods}{Matrix<T> submatrix(int startRow, int startCol, int endRow, int endCol)}

    This method's signature is long. An automatic linebreak is inserted,
    which results in underful hbox (badness 10000).


The resulting document looks like I expected, but in the original document which is rather long, all the underful hbox warnings make it difficult to notice real problems.

Is it possible to suppress the underful hbox warnings only when they occur in this specific environment?

Short explanation of the environment: I want to have a variable text "Method", "Methods", "Constructors" or similar on the left, and a left-aligned list of methods right of it. I'm open to suggestions how to acheive that in a different way.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

I'd suggest to use varwidth instead of \pbox; the problem seems to be in \lstinline, a \raggedright declaration inside varwidth should cure the problem. I'd also measure more precisely the width of your code box.




Still, I don't understand how you can manage five final optional arguments. It's not the best way to proceed, in my opinion.

share|improve this answer
thanks. so the \wd0\relax\box0 calculates the width used by the contents of \sbox0? –  crater2150 Mar 3 '13 at 18:44
regarding the optional arguments: I know, that it is not a good solution, I wanted to have a look at using a comma-separated parameter after I know the rest of the code won't need any bigger changes for solving the hbox problem ;) –  crater2150 Mar 3 '13 at 18:47
add comment

Your Answer


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.