I know this question has been asked before, but I could not find a suitable answer, so please bear with me.
I want to put a figure in my document using the wrapfigure
environment. It is supposed to be on the left side of the document with width = 0.25\textwidth
. I have used a flushleft
environment within the wrapfigure
environment to keep everything formatted properly. This works fine in some parts of the document, but in others the figure ends up in the middle of the page, with body text over it.
I have noticed that this happens near long blocks of text. If I have a figure that is supposed to be to the left of a long block of body text, then it messes up. However, if I break the text up into smaller paragraphs and put the wrapfigure
environment between them, it works. The problem is that I don't want my paragraphs to be broken in strange places to accommodate my figures. There must be a better way of formatting this. Thanks in advance for your help!
Note: I don't think there are no page breaks in the problem area. I saw that this was a problem for one person, so I thought I should point that out ahead of time. Besides body text, there are only breaks for sections
and displayed equations. Of course, I'm no expert at typesetting so I could be wrong.
[Edit]: Here is my MWE. I realize it isn't exactly minimal, but it's the best I could do without making the problem disappear.
\documentclass[]{amsart}
\usepackage{amsmath,amssymb}
\usepackage{tikz}
\usepgflibrary{shapes}
\usepackage{wrapfig}
\usepackage{caption}
\usepackage{lipsum}
\begin{document}
\captionsetup{justification=raggedright,singlelinecheck=false}
\pgfmathsetmacro{\ex}{0}
\pgfmathsetmacro{\ey}{0}
\newcommand{\figureone}[1]{
\begin{tikzpicture}[#1]
\draw [fill = lightgray] (0,0) circle [radius = 1.25 cm];
\draw (0,0) -- (0.8838834765,0.8838834765);
\node [above left] at (0.5,0.5) {$r$};
\node [above left] at (-1.0,0.575) {$C$};
\draw [->] (\ex,\ey) ++(135:1.5cm) arc (135:85:1.5cm);
\draw [->] (\ex,\ey) ++(160:1.5cm) arc (160:210:1.5cm);
\end{tikzpicture}
}
\newcommand{\figuretwo}[1]{
\begin{tikzpicture}[#1]
\draw [fill = lightgray] rectangle (2,2);
\node [right, rotate=90] at (2.35,0.4) {1 unit};
\node [below] at (1,-0.1) {1 unit};
\node [above] at (1,1) {$A = 1$};
\node [below] at (1,1) {$\textrm{unit}^2$};
\draw [<-] (0,-0.375) -- (0.35,-0.375);
\draw [->] (1.65,-0.375) -- (2,-0.375);
\draw (0,-0.15) -- (0,-0.6);
\draw (2,-0.15) -- (2,-0.6);
\draw [<-](2.375,0) -- (2.375,0.35);
\draw [->](2.375,1.65) -- (2.375,2);
\draw (2.15,0) -- (2.6,0);
\draw (2.15,2) -- (2.6,2);
\end{tikzpicture}
}
\begin{wrapfigure}{l}{0.25\textwidth}
\begin{flushleft}
\figureone{}
\end{flushleft}
\caption{Caption}
\end{wrapfigure}
\noindent
Filler text: here is some filler text. In my document this is 7 lines long, including one displayed equation. The first figure should be positioned directly to the right of this text.
\section*{Section 1}
\begin{wrapfigure}{l}{0.25\textwidth}
\begin{flushleft}
\figuretwo{}
\end{flushleft}
\caption{Caption}
\end{wrapfigure}
\lipsum[1]
\section*{Section 2}
\lipsum[2-3]
\end{document}
Best Answer
You need to have enough text in order to surround your images with it. When I add some dummy-text here, it works just fine.
If you do not have enough text, you can use a
multicolumn
environment or you put it in atabbing
or a simpletabular
. This will make it less flexible but fully controllable.