I'm using package "color" to have a green text box with black text, and my code is -

\textbf{\fcolorbox{black}{green!30}{black text on a boxed green background}}

How can I get it to wrap lines please?

If it can't wrap with 'fcolorbox', what command would have the same effect and would wrap please?

  • You want to look at the tcolorbox package. – egreg Apr 20 '15 at 18:11
  • If you want this coloured box to wrap inside the text just like other normal text, then you're probably interested in Cool text highlighting ((duplicate)) – Werner Apr 20 '15 at 18:35
  • Thanks @Werner, I knew I answered some Q like this before but couldn't find it through the search. Not that my answer is the accepted one... – Martin Scharrer Apr 20 '15 at 18:45
  • @boudiccas: The soul and ulem packages were written to highlight (underline, background color, etc.) flowing text and might do something similar what you want. Don't think they can create exactly the same style like \fcolorbox, through. – Martin Scharrer Apr 20 '15 at 18:48

I suggest one of my favourite packages: tcolorbox


% A new `\tcbox` command

\newtcbox{\highlight}[0]{boxsep=0pt,left=0pt,top=0pt,bottom=0pt,right=0pt,boxrule=0pt,arc=0pt,auto outer arc,colback=green,width=6cm}


\highlight{black text on a boxed green background}

black text on a boxed green background

black text on a boxed green background

\begin{tcolorbox}[width=6cm,colback=green,arc=0pt,auto outer arc]
black text on a boxed green background


enter image description here

  • But this isn't really feasible for just boxing and highlighting words or sentences as part of a paragraph. – boudiccas Apr 20 '15 at 18:31
  • @boudiccas: At what point in your post did you mention the highlighting? ;-) – user31729 Apr 20 '15 at 19:22
  • @ChristianHupfer in comments on my answer:-) – David Carlisle Apr 20 '15 at 19:38
  • @DavidCarlisle: Those comments were made after I posted my solution ;-) – user31729 Apr 20 '15 at 19:55
  • and after mine:-) – David Carlisle Apr 20 '15 at 20:03

\fcolorbox is like \fbox or \mbox and makes a horizontal (LR) box, so you need

   \parbox{3cm}{black text on a boxed green background}}}

replacing 3cm by whatever width you need.

  • So I can't use it as an item in a sentence then? Like this In some places you may see a little \textbf{\fcolorbox{black}{green!30}{black text on a boxed green background}} round a word or two, these show that they are a common side-effect, – boudiccas Apr 20 '15 at 18:06
  • @boudiccas no (you could not use \fbox in that way either) if you want coloured highlighting within a paragraph look at ulem or soul packages – David Carlisle Apr 20 '15 at 18:09
  • I'm looking for commands that will give me red, green, blue or yellow boxes, and neither package seem to be able to do it. Any other ideas please? – boudiccas Apr 20 '15 at 18:23

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