[Tex/LaTex] Set background color of a box with predefined width

boxescolorminipage

I would like to have something like a minipage with colored background, i.e. a box where you can predefine the width and the background color. My attempt

\colorbox{green}{\begin{minipage}{\slwidth}
Some text
\end{minipage}}

lead to a box which was a bit wider than the original minipage. Any suggestions?

Best Answer

You have to set \fboxsep=0pt to avoid the extra padding around the minipage. Try this:

\documentclass{article}
\usepackage{xcolor}
\begin{document}
\fboxsep0pt
\colorbox{green}{\begin{minipage}{3cm}
  Some text
\end{minipage}}

\fboxrule.2pt\fboxsep-.2pt
\fbox{\begin{minipage}{3cm}
Some text
\end{minipage}}
\end{document}