×
点此以英语 使用 ShareLaTeX

[edit] ShareLaTeX guides

[edit] LaTeX Basics

[edit] Mathematics

[edit] Figures and tables

[edit] References and Citations

[edit] Languages

[edit] Document structure

[edit] Formatting

[edit] Fonts

[edit] Presentations

[edit] Commands

[edit] Field specific

[edit] Class files

At time, it might be desirable to wrap text around a float (a figure, in our case) so as not to break the flow of the text. There are a number of packages in LaTex to accomplish this task, though they requires some amount of manual tuning in most of the cases.

[edit] Using wrapfig

The wrapfig package may not come with the default installation of LaTeX, and additional package installation may be required.

To use wrapfig, we need to include the following line in preamble -

\usepackage{wrapfig}

This makes the wrapfigure environment available to us, and we can put a \includegraphics command inside it to create a figure around which text will be wrapped. Here is how we can specify a wrapfigure environment -

\begin{wrapfigure}[lineheight]{position}{width}
  ...
\end{wrapfigure}


The position parameter has eight possible values -

r R right side of the text
l L left side of the text
i I inside edge–near the binding (in a twoside document)
o O outside edge–far from the binding

The uppercase version allows the figure to float. The lowercase version means exactly here.

Here is an example -

\begin{wrapfigure}{r}{0.5\textwidth}
  \begin{center}
    \includegraphics[width=0.48\textwidth]{birds}
  \end{center}
  \caption{Birds}
\end{wrapfigure}

It may be noted that the width of the image included was specified relative to width of the text (\textwidth). It is a good idea to use relative sizes to define lengths (height, width, etc), particularly when using wrapfigure.

In the example above, the figure covers exactly half of the the textwidth, and the actual image uses a slightly smaller width, so that there is a pleasing small white frame between the image and the text. The image should always be smaller (less wide) than the wrap, or it will overrun the text.

[edit] Dealing with Images with white space

In case the image has undesirable white space, we can use any of the following options to remove the extra whitespace -

  • trim the white space when using \includegraphics
  • The picins package may be used instead of wrapfigure, which removes the extra white space out of the box without any manual tuning.
  • The package floatflt is another alternative.
  • Avoid using \begin{center} to center the image, it adds extra space. Use \centering instead.
  • The program pdfcrop (included in most tex installations) may be used to remove the white space permanently.