# Wrapping images in text without inducing ugly justified text

I am trying to put a small image inside a paragraph. I don't care where it goes in the paragraph as long as it is on the right and text flows around it. I don't want it before or after the text.

This is what I have so far, but it results in an ugly justification of the text above the image. For some reason I am telling it to start a new paragraph with the wrapped text when that's not what I want.

A's height measures 4.0 feet. With only the Y mutation present, A's height measures 4.6 feet.
\begin{wrapfigure}{r}{0.5\textwidth}
\centering
\includegraphics[width=0.4\textwidth]{epistasisExample.png}
\caption{2-way Epistasis Example}
\label{fig:EpistasisEG}
\end{wrapfigure}
Each mutations affects the observed height: X reduces it by 0.5 feet, and Y increases it by

-
have you tried using \RaggedRight to make the text flush right? –  myrtille Feb 12 '13 at 14:24
Hmm still having problems. The best I can do is put the image at the top of the text, but it enlarges the paragraph spacing for the paragraph break right before the text and image paragraph. –  SwimBikeRun Feb 12 '13 at 14:58
Maybe try relaxing where the figure is positioned by using a capital R instead: \begin{wrapfigure}{R}{0.5\textwidth} –  myrtille Feb 12 '13 at 15:32
You shouldn't put the wrapfig in the middle of a paragraph. Or to quote the documentation (in wrapfig.sty): "if you want placement in the middle of a paragraph, you must put the environment between two words where there is a natural line break." –  Ulrike Fischer Feb 12 '13 at 16:17
@Ulrike: Oops, your comment was a bit faster than my answer. –  Hendrik Vogt Feb 12 '13 at 16:24

This as an answer to be able to include an image and the sample code to see if that is what you want. If not, can you tell me what it is that bothers you?

The code:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{wrapfig}
\begin{document}
A's height measures 4.0 feet. With only the Y mutation present, A's height measures 4.6 feet.
\begin{wrapfigure}{R}{0.5\textwidth}
\includegraphics[width=0.4\textwidth]{example-image}
\caption{2-way Epistasis Example}
\label{fig:EpistasisEG}
\end{wrapfigure}

Each mutations affects the observed height: X reduces it by 0.5 feet, and Y increases it by
\end{document}

-

It's unfortunate, but wrapfig is not quite designed for what you want. From the package documentation:

if you want placement in the middle of a paragraph, you must put the environment between two words where there is a natural line break.

Thus, you first have to find the natural line break by leaving away the wrapfigure, as I did for the code below.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{wrapfig}
\begin{document}
A's height measures 4.0 feet. With only the Y mutation present, A's height measures 4.6 feet.
Each mutations affects the observed height: X reduces it by
\begin{wrapfigure}{r}{0.5\textwidth}
\centering
\includegraphics[width=0.4\textwidth]{epistasisExample.png}
\caption{2-way Epistasis Example}
\label{fig:EpistasisEG}
\end{wrapfigure}
0.5 feet, and Y increases it by
whatever and some more text to show wrapping.
\end{document}

-