9

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?

13

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}
  • 1
    Using a group the setting will be local. – egreg Apr 1 '13 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. – Yiannis Lazarides Apr 1 '13 at 20:03
  • Possibly a very thin padding is better. – egreg Apr 1 '13 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. – JF Meier Apr 2 '13 at 19:45
0

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}
  • 2
    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 '14 at 0:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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