2

I'm trying to realise switching between wrapfigure and figure environments, using boolean control. But for some reason wrapfigure does not do what it should do - be wrapped, instead it is placed in the end of the text.

enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{lipsum}
\usepackage{ifthen}
\newboolean{Figure} 
\setboolean{Figure}{true}

\newenvironment{WrapFigure}[3]
{
\ifthenelse{\boolean{Figure}}{\begin{wrapfigure}[#1]{#2}{#3}}{\begin{figure}}   
        }
        {   
\ifthenelse{\boolean{Figure}}{\end{wrapfigure}}{\end{figure}}       
}

\begin{document}

\lipsum[1-2]
\begin{WrapFigure}{14}{r}{0.35\linewidth}
    \centering
    \includegraphics[draft,width=0.38\linewidth]{NICE Figure.pdf}
    \caption{XXXXXXXX XXXXXXXXXXXXXX XXXXXXXXXXXXX }
\end{WrapFigure}
\lipsum[1-2]

\end{document}
2

You are using a group around wrapfigure, that makes it choke.

\documentclass{article}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{lipsum}
\usepackage{ifthen}
\usepackage{xparse}

\newboolean{Figure} 
\setboolean{Figure}{true}

\NewDocumentEnvironment{WrapFigure}{omm}
 {%
  \ifFigure
    \IfNoValueTF{#1}
      {\wrapfloat{figure}{#2}{#3}}
      {\wrapfloat{figure}[#1]{#2}{#3}}%
  \else
    \figure
  \fi
 }
 {%
  \ifFigure
    \endwrapfloat
  \else
    \endfigure
  \fi
 }

\begin{document}

\lipsum[1-2]

\begin{WrapFigure}[14]{r}{0.35\linewidth}
    \centering
    \includegraphics[draft,width=0.38\linewidth]{NICE Figure.pdf}
    \caption{XXXXXXXX XXXXXXXXXXXXXX XXXXXXXXXXXXX }
\end{WrapFigure}

\lipsum[1-2]

\end{document}

(the \ifFigure syntax is simpler, in this case, I believe). With xparse it's easy to keep the syntax of wrapfig.

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.