14

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?

1
  • Add \fboxsep0pt before.
    – yannisl
    Apr 1, 2013 at 19:23

2 Answers 2

17

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}
4
  • 1
    Using a group the setting will be local.
    – egreg
    Apr 1, 2013 at 19:54
  • @egreg True. I am not too sure what the OP wants though, as a colorbox without a bit of padding does not look very sexy.
    – yannisl
    Apr 1, 2013 at 20:03
  • Possibly a very thin padding is better.
    – egreg
    Apr 1, 2013 at 20:12
  • I works well; the aim is to produce boxes of given width which can be converted to images by the "preview"-package. Apr 2, 2013 at 19:45
2

Test this. Wrapfigure is optional, but I like adding it and I like that it works!

\usepackage{wrapfig}
\definecolor{light-gray}{gray}{0.95}
\usepackage{tcolorbox}

\begin{wrapfigure}{r}{7cm}  
\begin{minipage}[t]{0.95\linewidth} 
\begin{tcolorbox}[colback=gray!5,colframe=green!40!black,title=In short]
Example text ... blabla         
\end{tcolorbox} 
\end{minipage}  
\end{wrapfigure}
1
  • 3
    Why do you use a wrapfigure? Does it really solve the 'old' question? A full example with some screenshot would be appreciated!
    – user31729
    Sep 22, 2014 at 0:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .