# Aligning a listing environment within a paragraph

I have the following code that displays a listing in a paragraph. However, because there are not so many line of code, I would like to move it to the right and the paragraph be on the left hand side. I'm wondering how I can do this.

\begin{minipage}{0.5\linewidth}
\vspace{-0.2cm}
\begin{lstlisting}[basicstyle=\scriptsize,label= mylabel, caption = mycaption}
LOC1
LOC2
LOC3
LOC4
\end{lstlisting}
\vspace{-0.2cm}
\end{minipage}

-
wrapfig is probably the package you are looking for –  David Carlisle Dec 17 '12 at 16:01

You can use the wrapfig package; a little example:

\documentclass{article}
\usepackage{wrapfig}
\usepackage{listings}
\usepackage{lipsum}% just to generate text for the example

\begin{document}

\begin{wrapfloat}{lstlisting}{O}{5cm}
\begin{lstlisting}[basicstyle=\scriptsize,label= mylabel, caption =mycaption]
LOC1
LOC2
LOC3
LOC4
\end{lstlisting}
\end{wrapfloat}
\lipsum[1-3]

\end{document}


-