# When using an image as the background of a minipage how to remove the black frame around it?

I have a question about a piece of code the moderator Martin Scharrer posted some time ago (so if you're there Martin, this one is for you). The question he was answering to was about using an image as the background of a minipage.

He posted this solution

\documentclass{article}

\usepackage{graphicx}

\newsavebox\mysavebox
\newenvironment{imgminipage}[2][]{%
\def\imgcmd{\includegraphics[width=\wd\mysavebox,height=\dimexpr\ht\mysavebox+\d    p\mysavebox\relax,#1]{#2}}%
\begin{lrbox}{\mysavebox}%
\begin{minipage}%
}{%
\end{minipage}
\end{lrbox}%
\sbox\mysavebox{\fbox{\usebox\mysavebox}}%
\mbox{\rlap{\raisebox{-\dp\mysavebox}{\imgcmd}}\usebox\mysavebox}%
}

\begin{document}

\begin{imgminipage}{imagefilename}{5cm}
Some text\\
Hello world!
\end{imgminipage}

\end{document}


When I use this code, however, the minipage has a black frame around the image. How can I modify it to get rid of the frame?

• Replace \fbox with \mbox. \fbox is for frame box. – Guido Dec 5 '16 at 20:03

\sbox\mysavebox{\fbox{\usebox\mysavebox}}

restores \mysavebox with an \fbox around it. Remove this line and your output should appear without the framed box.
• @Gabu: Then you may want to keep the \fbox, but add \setlength{\fboxrule}{0pt} to your preamble. This will remove the rule around the image, but keep the \fboxsep white space around it. – Werner Dec 5 '16 at 20:22
• The default \fboxsep is 3pt. You could add \setlength{\fboxsep}{6pt} to your preamble to change this globally, or at the start of your imgminipage environment (similar for \fboxrule) to limit it to that specific environment. You can also do something like \setlength{\fboxsep}{1.5\fboxsep} to increase the current \fboxsep by 50%. – Werner Dec 5 '16 at 20:52