Overfull \hbox problem with colorbox

755 views
Skip to first unread message

T0m4S

unread,
Sep 17, 2010, 7:57:09 AM9/17/10
to LaTeX Users Group
Hi!

I want to get some text on a colored box so I used the package color
with the following options on my preamble:

\usepackage[usenames]{color}

The problem is that as the text I want to have in the box is larger
that a line latex gives a overfull \hbox error. I want to know if
there's an option to avoid it so that automatically it puts the text
over several lines without giving this problem...

Thanks!

Peter Flynn

unread,
Sep 17, 2010, 11:12:50 AM9/17/10
to latexus...@googlegroups.com
On Fri, Sep 17, 2010 at 12:57 PM, T0m4S <tom...@gmail.com> wrote:
Hi!

I want to get some text on a colored box so I used the package color

The color package is obsolete and only kept for backward compatibility.
Use the package xcolor instead.
 
with the following options on my preamble:

\usepackage[usenames]{color}

See the xcolor documentation for all the other names. I use [svgnames] but there are many.
 
The problem is that as the text I want to have in the box is larger that a line latex gives a overfull \hbox error. I want to know if there's an option to avoid it so that automatically it puts the text over several lines without giving this problem...

OK, so this is nothing to do with color. It's about how to fit text in a box.
Unfortunately, you haven't told us what command you are using to do this.

\colorbox is like \fbox: it is only as high as the material it contains and it cannot directly contain multi-line material. However, if you put the text in something else first, such as a \parbox or a minipage environment, you can then put that inside a \colorbox. Here's a simple solution using \parbox:

\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{lipsum}
\begin{document}
\fboxsep1em
\colorbox{ForestGreen}{\parbox{2in}{\color{white}\lipsum[1]}}

\end{document}

The \fboxsep dimension is used by \colorbox as well as \fbox to specify the space between the contents and the edge of the box.

If you want more complex contents, use the Sbox environment from the fancybox package. This saves the contents in a box which you can then manipulate more easily; and more importantly you can use it in a macro of your own:

\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{fancybox,lipsum}
\begin{document}
Here is an example:

\begin{Sbox}
  \begin{minipage}{3in}\color{Brown}\tiny\sffamily
    \lipsum[2]
    \begin{itemize}
      \item \lipsum[22]
      \item \lipsum[45]
    \end{itemize}
  \end{minipage}
\end{Sbox}
{\fboxsep1em\flushright\colorbox{CornflowerBlue}{\TheSbox}\par}

\end{document}

Sbox saves the contents, and \TheSbox emits it. You can do the same by hand with a \newsavebox and other commands but I don't bother when fancybox provides it all.

///Peter

Arne Hallam

unread,
Sep 17, 2010, 8:48:10 PM9/17/10
to latexus...@googlegroups.com, Peter Flynn
So based on Pete's suggestion, I created the following file.


\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{fancybox,lipsum}
\begin{document}
\fboxsep1em
\colorbox{ForestGreen}{\parbox{2in}{\color{white}\lipsum[1]}}
Here is an example:
\begin{Sbox}
  \begin{minipage}{3in}\color{Brown}\tiny\sffamily
    \lipsum[2]
    \begin{itemize}
      \item \lipsum[22]
      \item \lipsum[45]
    \end{itemize}
  \end{minipage}
\end{Sbox}
{\fboxsep1em\flushright\colorbox{CornflowerBlue}{\TheSbox}\par}
\end{document}


I don't have any overfull errors, but I get the following.


Underfull \hbox (badness 1881) in paragraph at lines 6--6 \OT1/cmr/m/n/10 rus elit, vestibu-lum ut, plac []


Underfull \hbox (badness 2556) in paragraph at lines 6--6 \OT1/cmr/m/n/10 ne-tus et male-suada fames ac []

LaTeX Font Info:    External font `cmex10' loaded for size (Font)              <7> on input line 6.
LaTeX Font Info:    External font `cmex10' loaded for size (Font)              <5> on input line 6.
LaTeX Font Info:    Try loading font information for OMS+cmss on input line 14.

LaTeX Font Info:    No file OMScmss.fd. on input line 14.

LaTeX Font Warning: Font shape `OMS/cmss/m/n' undefined (Font)              using `OMS/cmsy/m/n' instead
(Font)              for symbol `textbullet' on input line 14. [1 ] (./boxes.aux)

LaTeX Font Warning: Some font shapes were not available, defaults substituted.  )



I am using TeXLive 2010 and frequently get warnings about over and unfill on boxes but not font missing errors.
--
You received this message because you are subscribed to the Google Groups "LaTeX Users Group" group.
To post to this group, send email to latexus...@googlegroups.com.
To unsubscribe from this group, send email to latexusersgro...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/latexusersgroup?hl=en.


-- 
with all thy getting get understanding---Proverbs 4:7.

The gentle art of being gentle---of kindness and forgiveness, sensitivity and thoughtfulness and generosity and humility and good old-fashioned love---have gone out of fashion.  Ironically, everyone is demanding their rights, and this demand is so shrill that it destroys one of the most basic rights, if we can put it like that: the right, or at least the longing and hope, to have a peaceful, stable, secure, and caring place to live, to be, to learn, and to flourish---N.T. Wright. 

In the wildness of speculation it has been suggested (of course more in jest than in earnest),that Europe ought to grow its corn in America, and devote itself solely to manufactures and commerce, as the best sort of division of the labour of the globe---Thomas Malthus, An Essay on the Principle of Population Book III, Chapter XII.

Arne Hallam
College of Liberal Arts and Sciences
237 Catt Hall
Iowa State University
Ames, IA 50011

aha...@iastate.edu
Work:	515-294-5861
FAX: 	515-294-1303
Home:	515-292-8739

Stephan Ronald

unread,
Sep 17, 2010, 11:14:21 PM9/17/10
to latexus...@googlegroups.com

Dear Tomas,
Can you try this one. I used soul package instead. The text provided inside is from lipsum package, since macros are not working as expected :-) I hope this will help u. Sorry for not answering to your actual question.

%__________________begin
\documentclass{article}
\usepackage{color,soul}
\begin{document}
\fboxsep1em

\setstcolor{blue}
\setulcolor{red}
\sethlcolor{yellow}

\ul{Quisque ullamcorper placerat ipsum. Cras nibh.
  Morbi vel justo vitae lacus tincidunt ultrices. Lorem ipsum dolor
  sit amet, consectetuer adipiscing elit. In hac habitasse platea
  dictumst. Integer tempus convallis augue. Etiam facilisis. Nunc
  elementum fermentum wisi. Aenean placerat. Ut imperdiet, enim sed
  gravida sollicitudin, felis odio placerat quam, ac pulvinar elit
  purus eget enim. Nunc vitae tortor. Proin tempus nibh sit amet nisl.
  Vivamus quis tortor vitae risus porta vehicula.

Fusce mauris. Vestibulum luctus nibh at lectus.
  Sed bibendum, nulla a faucibus semper, leo velit ultricies tellus,
  ac venenatis arcu wisi vel nisl. Vestibulum diam. Aliquam
  pellentesque, augue quis sagittis posuere, turpis lacus congue quam,
  in hendrerit risus eros eget felis. Maecenas eget erat in sapien
  mattis porttitor. Vestibulum porttitor. Nulla facilisi. Sed a turpis
  eu lacus commodo facilisis. Morbi fringilla, wisi in dignissim
  interdum, justo lectus sagittis dui, et vehicula libero dui cursus
  dui. Mauris tempor ligula sed lacus. Duis cursus enim ut augue. Cras
  ac magna. Cras nulla. Nulla egestas. Curabitur a leo. Quisque
  egestas wisi eget nunc. Nam feugiat lacus vel est. Curabitur
  consectetuer.}
 
\st{Sed commodo posuere pede. Mauris ut est. Ut
  quis purus. Sed ac odio. Sed vehicula hendrerit sem. Duis non odio.
  Morbi ut dui. Sed accumsan risus eget odio. In hac habitasse platea
  dictumst. Pellentesque non elit. Fusce sed justo eu urna porta
  tincidunt. Mauris felis odio, sollicitudin sed, volutpat a, ornare
  ac, erat. Morbi quis dolor. Donec pellentesque, erat ac sagittis
  semper, nunc dui lobortis purus, quis congue purus metus ultricies
  tellus. Proin et quam. Class aptent taciti sociosqu ad litora
  torquent per conubia nostra, per inceptos hymenaeos. Praesent sapien
  turpis, fermentum vel, eleifend faucibus, vehicula eu, lacus.

Pellentesque habitant morbi tristique senectus
  et netus et malesuada fames ac turpis egestas. Donec odio elit,
  dictum in, hendrerit sit amet, egestas sed, leo. Praesent feugiat
  sapien aliquet odio. Integer vitae justo. Aliquam vestibulum
  fringilla lorem. Sed neque lectus, consectetuer at, consectetuer
  sed, eleifend ac, lectus. Nulla facilisi. Pellentesque eget lectus.
  Proin eu metus. Sed porttitor. In hac habitasse platea dictumst.
  Suspendisse eu lectus. Ut mi mi, lacinia sit amet, placerat et,
  mollis vitae, dui. Sed ante tellus, tristique ut, iaculis eu,
  malesuada ac, dui.  Mauris nibh leo, facilisis non, adipiscing quis,
  ultrices a, dui.}
 
\hl{Sed feugiat. Cum sociis natoque penatibus et
  magnis dis parturient montes, nascetur ridiculus mus. Ut
  pellentesque augue sed urna. Vestibulum diam eros, fringilla et,
  consectetuer eu, nonummy id, sapien. Nullam at lectus. In sagittis
  ultrices mauris. Curabitur malesuada erat sit amet massa. Fusce
  blandit. Aliquam erat volutpat.  Aliquam euismod. Aenean vel lectus.
  Nunc imperdiet justo nec dolor.
 
Etiam euismod. Fusce facilisis lacinia dui.
  Suspendisse potenti. In mi erat, cursus id, nonummy sed, ullamcorper
  eget, sapien. Praesent pretium, magna in eleifend egestas, pede pede
  pretium lorem, quis consectetuer tortor sapien facilisis magna.
  Mauris quis magna varius nulla scelerisque imperdiet. Aliquam non
  quam. Aliquam porttitor quam a lacus. Praesent vel arcu ut tortor
  cursus volutpat. In vitae pede quis diam bibendum placerat. Fusce
  elementum convallis neque. Sed dolor orci, scelerisque ac, dapibus
  nec, ultricies ut, mi. Duis nec dui quis leo sagittis commodo.}

\end{document}
 
%__________________end
--
Stepen Ronald

Stephan Ronald

unread,
Sep 17, 2010, 11:29:29 PM9/17/10
to latexus...@googlegroups.com
On Sat, Sep 18, 2010 at 6:18 AM, Arne Hallam <aha...@iastate.edu> wrote:
So based on Pete's suggestion, I created the following file.


\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{fancybox,lipsum}
\begin{document}
\fboxsep1em
\colorbox{ForestGreen}{\parbox{2in}{\color{white}\lipsum[1]}}
Here is an example:
\begin{Sbox}
  \begin{minipage}{3in}\color{Brown}\tiny\sffamily
    \lipsum[2]
    \begin{itemize}
      \item \lipsum[22]
      \item \lipsum[45]
    \end{itemize}
  \end{minipage}
\end{Sbox}
{\fboxsep1em\flushright\colorbox{CornflowerBlue}{\TheSbox}\par}
\end{document}


I don't have any overfull errors, but I get the following.


Underfull \hbox (badness 1881) in paragraph at lines 6--6 \OT1/cmr/m/n/10 rus elit, vestibu-lum ut, plac []


Underfull \hbox (badness 2556) in paragraph at lines 6--6 \OT1/cmr/m/n/10 ne-tus et male-suada fames ac []



Yes. It is because Peter gave 2in for the parbox and some text cannot have a hyphenation patten when it is set at 2in. Hence it complaints about the underfull hbox. If you increase it to 4in the problem will be solved.

And this is not a TexLive problem.
--
Stepen Ronald

Stephan Ronald

unread,
Sep 17, 2010, 11:26:35 PM9/17/10
to latexus...@googlegroups.com


2010/9/18 Stephan Ronald <s.rona...@gmail.com>
On Fri, Sep 17, 2010 at 5:27 PM, T0m4S <tom...@gmail.com> wrote:
Hi!

I want to get some text on a colored box so I used the package color
with the following options on my preamble:

\usepackage[usenames]{color}

The problem is that as the text I want to have in the box is larger
that a line latex gives a overfull \hbox error. I want to know if
there's an option to avoid it so that automatically it puts the text
over several lines without giving this problem...

Dear Tomas,
Can you try this one. I used soul package instead. The text provided inside is from lipsum package, since macros are not working as expected :-) I hope this will help u. Sorry for not answering to your actual question.

%__________________begin
\documentclass{article}
\usepackage{color,soul}
\begin{document}
\fboxsep1em
s ut, mi. Duis nec dui quis leo sagittis commodo.}

...
 

\end{document}
 
%__________________end

I am very sorry. This was not the answer for the question. Please ignore.

--
Stepen Ronald
Reply all
Reply to author
Forward
0 new messages