[Tex/LaTex] colorbox around parbox too big

backgroundsboxes

I want to typset some text with colored background and outline, that spans the whole \textwidth. I tried to get this with a colorbox surrounding a parbox. It works in some way, but the colorbox is always a bit bigger than the parbox, causing the colored fill to overlap the outline a bit:
colored fill overlaps outline

Is there any way to fix this? I didn't find one. The corresponding code:

\newcommand{\information}[1]{\colorbox{DarkOliveGreen2}{\fboxsep4mm\framebox[\textwidth][l]{\parbox{\linewidth}{\textbf{foo: } #1}}}}

Any ideas are greatly appreciated. Thanks!

Edit: As supposed in the comments: I already tried removing or changing the \fboxsep-value, but it doesn't change the behavior. Just the space between the text and the border of the boxes tightens, and I want that space…

Best Answer

The space between the box edges and the real content is ruled by \fboxsep as for the usual \fbox command.

Since \fboxsep4mm appears explicitly in the \information macro definition there's no chance to change the \fboxsep value before. 4mm seems to be definitely too much, but this is a matter of taste, of course.

In my point of view, there's no need of using an additional \framebox command, since \fcolorbox is also available.

\documentclass{article}

\usepackage[x11names]{xcolor}
\begin{document}


\newcommand{\information}[2][0pt]{%
  \fboxsep=#1%
  \par\noindent%
  \fcolorbox{black}{DarkOliveGreen2}{%
    \parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule}{\textbf{foo: }#2}%
  }% Reduce the box size by 2 \fboxsep and 2\fboxrule widths. 
}


\information[2pt]{Foo}

\end{document}

enter image description here