Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In the example file below, using amsart and compiling using pdflatex, the equation crashes into the space reserved for the wrapfigure. If I use article instead of amsart, then the problem goes away (the equation is centered in the column of text instead centered in the page). However, I'd like to use amsart... Suggestions?

\documentclass[12pt]{amsart}

\usepackage[top=30mm, bottom=30mm, left=30mm, right=30mm]{geometry}
\usepackage{wrapfig}

\begin{document}

\title{Test File}

\author{Dr Foo Bar}
\date{\today}

\begin{abstract}
A test file.
\end{abstract}
\maketitle

\section{Lorem ipsum}

\subsection{Dolor sit amet}

\begin{wrapfigure}[16]{r}{0.5\textwidth}

\vspace{1.5in}
\caption{Fusce tempor, diam nec hendrerit luctus, purus quam...}
\end{wrapfigure}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus
congue eros a purus vestibulum condimentum. Curabitur pretium lacinia
tempus. Quisque auctor ornare ipsum, ac aliquet nulla tincidunt
eu. Vivamus sit amet metus in erat placerat commodo. Duis blandit
dignissim tempus.
\[
i^2 = j^2 = k^2 = ijk = -1.
%%% Why isn't the centering aware of the wrapfigure?
\]
Proin varius vel eros nec mollis. Vivamus sit amet
ligula a nunc malesuada malesuada mollis eu tellus. Vestibulum
lobortis sapien sit amet lacus tristique, ut facilisis sapien
mollis. Suspendisse placerat ante tortor, molestie blandit arcu
sodales sed. Aliquam vitae ligula nisi. Donec tempor, ante a vehicula
hendrerit, ligula lacus elementum dolor, vitae hendrerit magna justo
in neque.
\end{document}
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

The amsart class wants all displays to be set centered with respect to the overall margins, in every situation. So for every display it executes \fullwidthdisplay, which in this case is unfortunately wrong.

You can do an ad hoc correction for this case:

\documentclass[12pt]{amsart}

\usepackage[top=30mm, bottom=30mm, left=30mm, right=30mm]{geometry}
\usepackage{wrapfig}

\begin{document}

\title{Test File}

\author{Dr Foo Bar}
\date{\today}

\begin{abstract}
A test file.
\end{abstract}
\maketitle

\section{Lorem ipsum}

\subsection{Dolor sit amet}

\begin{wrapfigure}[16]{r}{0.5\textwidth}

\vspace{1.5in}
\caption{Fusce tempor, diam nec hendrerit luctus, purus quam...}
\end{wrapfigure}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus
congue eros a purus vestibulum condimentum. Curabitur pretium lacinia
tempus. Quisque auctor ornare ipsum, ac aliquet nulla tincidunt
eu. Vivamus sit amet metus in erat placerat commodo. Duis blandit
dignissim tempus.
\[\displaywidth=\parshapelength\numexpr\prevgraf+2\relax
i^2 = j^2 = k^2 = ijk = -1.
\]
Proin varius vel eros nec mollis. Vivamus sit amet
ligula a nunc malesuada malesuada mollis eu tellus. Vestibulum
lobortis sapien sit amet lacus tristique, ut facilisis sapien
mollis. Suspendisse placerat ante tortor, molestie blandit arcu
sodales sed. Aliquam vitae ligula nisi. Donec tempor, ante a vehicula
hendrerit, ligula lacus elementum dolor, vitae hendrerit magna justo
in neque.

\end{document}

that tells LaTeX how wide is the line where the display should appear; \prevgraf returns the number of lines before the display (in this case 8), we add 2 because conventionally displays occupy three lines; with \parshapelength 10 we access the length of the tenth line in the paragraph as established by wrapfig, but we don't need to know the number, because TeX can compute it with \numexpr\prevgraf+2\relax.

enter image description here

For multiline alignment environments the trick is different, because we can't set \displaywidth inside them. Here's a proposal:

\newenvironment{wrapped}[1]
 {\def\wrappedcurrent{#1}%
  \setlength{\columnwidth}{\parshapelength\numexpr\prevgraf+2\relax}%
  \csname #1\endcsname}
 {\csname end\wrappedcurrent\endcsname}

Thus, in the scope of a wrapfig, you can say, for instance,

\begin{wrapped}{align}
a&=b\\
c&=d
\end{wrapped}

The argument can be any of align, align*, gather, gather*, multline or multline*. You can even say \begin{wrapped}{alignat}{2} or \begin{wrapped}{alignat*}{2}.

Don't use wrapped elsewhere than in the scope of wrapfig: you've been warned. And don't use wrapfig. ;-)

share|improve this answer
    
I don't understand it, but it works! How about align environments? What is the magic spell for those? –  Sam Nead Jul 16 '13 at 13:01
    
@SamNead Added. –  egreg Jul 16 '13 at 13:15
    
I'll give these a try. Thank you very much for the magic.... Ok, and a question - what should I use instead of wrapfig? I've got lots of small figures, and I want to flow text around them - it looks nicer that having big horizontal blocks of white space. Is there something better than wrapfig? –  Sam Nead Jul 17 '13 at 22:23
    
@SamNead I'm not very keen about text floating around figures, just that. –  egreg Jul 17 '13 at 22:26
    
ok, thanks again. –  Sam Nead Jul 17 '13 at 22:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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