# Why does my graphics flows out of the box?

I'm new to LaTeX, and have been struggling with what I think should be simple.

I want to create a box with a blue border and yellow interior. Inside of the box should be a graphic on the left, and text on the right. Seems simple, and I have gotten it to work, but this will be generated from a database, so text length is variable. It currently works if after the text I add vspace to fill out the box to the height of the graphic. Otherwise, the box is only the height of the text, and the image spill out the bottom.

The code I am using is:

\noindent{\fboxsep=.3pt\framebox{\colorbox{newyell}{
\parbox{\textwidth}{
\begin{wrapfigure}{l}{0.4\textwidth}
\vspace{-35pt}
\begin{center}
\includegraphics[width=0.35\textwidth]{img_0236.jpg}
\end{center}
\end{wrapfigure}

\phantom{0}\textcolor{blue}{
{\bf Test:}\ My test line\newline
\phantom{0}\ this is a tesrt\newline
\phantom{0}\ this is a tesrt\newline
\phantom{0}\ this is a tesrt\newline
\phantom{0}\ this is a tesrt\newline
\phantom{0}\ this is a tesrt\newline
}
}
%\vskip80pt
}}}
}


If I enable the \vskip, the box is the right size, otherwise it is too short. Since it comes from a database with variable length text, I can't hard code a value.

What am I doing wrong?!?!?

-
Welcome to tex.sx! Note that you don't have to (and shouldn't) sign with your name since it automatically appears in the lower right corner of your post. –  Hendrik Vogt Jan 23 '11 at 7:51
@all high rep users: This question has already been edited by TH, lockstep and myself. If other users edit it, too, it would become CW, as described on meta.SO. (I'm not sure if it needs one or two additional editors; at the link it says that "at least five" different editors make a question CW, but it doesn't say if this is including or excluding the OP.) –  Hendrik Vogt Jan 23 '11 at 9:15
@Hendrik: I just wanted to edit the question title (to be something better than "XXX question") ... if you think the question should not become community wiki, please do this instead of me. (My proposal: How can I avoid my graphics overflowing the box?). –  Paŭlo Ebermann Aug 14 '11 at 11:58
@Paŭlo: Don't worry, title edits don't count towards CW. Just make sure you don't touch the body. –  Hendrik Vogt Aug 14 '11 at 13:00

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{wrapfig,xcolor,ragged2e,tabularx,calc}

\begin{document}

\noindent
\fcolorbox{black}{yellow!40}{%
\begin{tabularx}{\linewidth-2\fboxsep-2\fboxrule}{@{}>{\Centering}p{0.4\textwidth}X@{}}
\vspace{0pt}\includegraphics[width=0.35\textwidth]{img_0236.jpg}
&
\vspace{0pt}
\phantom{0}\color{blue}%
{\bf Test:}~My test line\newline
\phantom{0}~this is a tesrt\newline
\phantom{0}~this is a tesrt\newline
\phantom{0}~this is a tesrt\newline
\phantom{0}~this is a tesrt\newline
\phantom{0}~this is a tesrt\newline
\end{tabularx}%
}
\end{document}


-
Works perfectly! Thanks, I've been fighting that one for awhile. –  Ryan Jan 23 '11 at 19:52
So why not approve the answer (Press the green hook) –  xeroc Jan 26 '11 at 11:06