Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to get text to wrap around my figure. This works fine in the main body of my text, but when I put it inside an \fcolorbox the text simply overwrites the image. I've reduced my code to the example below. Being new here I apologize if I'm doing this wrong, but I don't see a link to upload a file, so I'm hoping people can reproduce this using any image file they have lying around.

\documentclass{book}
\usepackage{graphicx} % Allows graphics to be imported
\usepackage{wrapfig} % Allows figures to go on the side of the page with text wrapping around them
\usepackage[usenames,dvipsnames]{color} % An easy way to get shaded boxes
\definecolor{light-gray}{gray}{0.8} % Defines the color we're using for shaded boxes

\begin{document}

\fcolorbox{black}{light-gray}{\begin{minipage}{\columnwidth}\parskip=6pt
Some text

\begin{wrapfigure}{r}{.2\textwidth}
\vspace{-15pt}
\begin{center}\includegraphics[width=.18\textwidth]{latexchapters/vectorsfigures/simplepath.png}\end{center}
\vspace{-15pt}
\end{wrapfigure}

{\it Answer:} To find the potential at $(x,y)$ we evaluate a line integral from the origin to $(x,y)$. For simplicity we use the path shown on the right, first going from $(0,0)$ to $(x,0)$ and then from there to $(x,y)$. Along the first segment only $f_x$ contributes, and since $y=0$, $f_x=1$ and the line integral equals $x$. Along the second segment only $f_y$ contributes, and $x$ is constant but $y$ is not, so we get $x\int_0^ye^{\tilde{y}}d\tilde{y} = xe^y-x$. Combining the two segments we find $\int_C\vec{f}=xe^y$. Remember that the gradient theorem just relates line integrals to gradients, but the definition of potential we use includes an additional minus sign, so $V(x,y)=-xe^y$.

\end{minipage}}

\end{document}
share|improve this question

migrated from stackoverflow.com Oct 15 '12 at 15:21

This question came from our site for professional and enthusiast programmers.

    
Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. –  Werner Oct 15 '12 at 15:37

1 Answer 1

Please note that the \it, \bf, etc. font macros are deprecated because they do not use the new font selection scheme introduced with LaTeX2e. Please use {\itshape ..}, {\bfseries ..} or \textit{..}, \textbf{..} instead. See Does it matter if I use \textit or \it, \bfseries or \bf, etc. and Will two-letter font style commands (\bf, \it, …) ever be resurrected in LaTeX? for more information.

Using \textit{...} solves the problem in your case (I've used example-image-a from the mwe package):

enter image description here

\documentclass{book}
\usepackage{graphicx }% Allows graphics to be imported
\usepackage{wrapfig} % Allows figures to go on the side of the page with text wrapping around them
\usepackage[usenames,dvipsnames]{color} % An easy way to get shaded boxes
\definecolor{light-gray}{gray}{0.8} % Defines the color we're using for shaded boxes

\begin{document}

\noindent
\fcolorbox{black}{light-gray}{\begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule}\parskip=6pt
Some text

\begin{wrapfigure}{r}{.2\textwidth}
\centering
\includegraphics[width=.18\textwidth]{example-image-a}
\end{wrapfigure}

\textit{Answer}: To find the potential at $(x,y)$ we evaluate a line integral from 
the origin to $(x,y)$. For simplicity we use the path shown on the right, first going 
from $(0,0)$ to $(x,0)$ and then from there to $(x,y)$. Along the first segment only 
$f_x$ contributes, and since $y=0$, $f_x=1$ and the line integral equals $x$. Along the 
second segment only $f_y$ contributes, and $x$ is constant but $y$ is not, so we get 
$x\int_0^ye^{\tilde{y}}d\tilde{y} = xe^y-x$. Combining the two segments we find 
$\int_C\vec{f}=xe^y$. Remember that the gradient theorem just relates line integrals to 
gradients, but the definition of potential we use includes an additional minus sign, so 
$V(x,y)=-xe^y$.

\end{minipage}}

\end{document}

I've also changed the following in your document:

  • Used \centering instead of the center environment. It removes the requirement to insert negative \vspaces;
  • Inserted \noindent before the \fcolorbox, since the default is to indent each paragraph with \parindent. This is not needed here; and
  • Made length of minipage equivalent to \linewidth-2\fboxsep-2\fboxrule to avoid an overfull \hbox warning - the \fcolorbox adds \fboxsep and \fboxrule on both sides of the box by default.
share|improve this answer
    
Thank you so much. That fixed the problem and fixed other problems in my Latex that I hadn't even realized I had. –  user1745844 Oct 15 '12 at 12:32
    
If I can quickly ask a quick follow-up question: For some reason the gray boxes have borders show up on some sides but not others. (In the example you posted the left and top are missing, but this doesn't seem to be consistent for me.) Do you know if there's a simple fix for that? –  user1745844 Oct 15 '12 at 12:48
    
This is a common problem and is only viewer-related. Your document should print fine, but viewers may mess up the rules due to snapping to pixels. You can increase the rule width, if needed, using \setlength{\arrayrulewidth}{1pt} (or whatever). See Adobe Reader and xcolor within a table breaks the line render. –  Werner Oct 15 '12 at 19:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.