2

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}
  • I'm not able to duplicate your problem. Could you please provide a MWE which illustrates the issue? – A.Ellett Jul 21 '13 at 22:52
  • @A.Ellett I tried to duplicate the problem myself on a new document, but couldn't. The only way I could do it was by modifying the actual code I used. I made this working example as short as possible, but it's hardly "minimal." When you compile this code (exactly as written), I believe it will illustrate the problem. – Randy Randerson Jul 21 '13 at 23:22
  • @fctaylor25 your example code shows that you are using wrapfigure in the wrong way: specifically, there's not enough text to wrap around the first wrapfigure. Perhaps this is what you meant? \section*{Section 1} \begin{wrapfigure}{l}{0.25\textwidth} \begin{flushleft} \figureone{} \end{flushleft} \caption{Caption} \end{wrapfigure} \lipsum[1] \section*{Section 2} \begin{wrapfigure}{l}{0.25\textwidth} \begin{flushleft} \figuretwo{} \end{flushleft} \caption{Caption} \end{wrapfigure} \lipsum[2-3] – Gonzalo Medina Jul 21 '13 at 23:47
  • In fact, no need for flushleft: \section*{Section 1} \begin{wrapfigure}{l}{0.25\textwidth} \figureone{} \caption{Caption} \end{wrapfigure} \lipsum[1] \section*{Section 2} \begin{wrapfigure}{l}{0.25\textwidth} \figuretwo{} \caption{Caption} \end{wrapfigure} \lipsum[2-3] – Gonzalo Medina Jul 22 '13 at 0:06
  • Thanks for the response, but removing flushleft doesn't change anything. Your code works, but you left out the filler text before section 1. When I put that in, the error comes back. – Randy Randerson Jul 22 '13 at 0:12
1

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 a tabbing or a simple tabular. This will make it less flexible but fully controllable.

% arara: pdflatex

\documentclass{amsart}
\usepackage{tikz}
\usepackage{wrapfig}
\usepackage{caption}
\captionsetup{justification=raggedright,singlelinecheck=false}
\usepackage{lipsum}
    \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{document}    
    \begin{wrapfigure}{l}{0.25\textwidth}
            \figureone{}
        \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}
            \figuretwo{}
            \caption{Caption}
        \end{wrapfigure}        
    \lipsum[1-3]    
    \section*{Section 2}    
    \lipsum[2-3]    
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.