| 1 |
\documentclass[pagesize=auto]{scrartcl} |
| 2 |
|
| 3 |
\usepackage{fixltx2e} |
| 4 |
\usepackage{etex} |
| 5 |
\usepackage{lmodern} |
| 6 |
\usepackage[T1]{fontenc} |
| 7 |
\usepackage{textcomp} |
| 8 |
\usepackage{amstext} |
| 9 |
\usepackage{array} |
| 10 |
\usepackage{xcolor} |
| 11 |
\usepackage{tikz} |
| 12 |
\usepackage{microtype} |
| 13 |
\usepackage{hyperref} |
| 14 |
|
| 15 |
\newcommand*{\mail}[1]{\href{mailto:#1}{\texttt{#1}}} |
| 16 |
\newcommand*{\pkg}[1]{\textsf{#1}} |
| 17 |
\newcommand*{\cls}[1]{\textsf{#1}} |
| 18 |
\newcommand*{\cs}[1]{\texttt{\textbackslash#1}} |
| 19 |
\makeatletter |
| 20 |
\newcommand*{\cmd}[1]{\cs{\expandafter\@gobble\string#1}} |
| 21 |
\makeatother |
| 22 |
\newcommand*{\env}[1]{\texttt{#1}} |
| 23 |
\newcommand*{\opt}[1]{\texttt{#1}} |
| 24 |
\newcommand*{\meta}[1]{\textlangle\textsl{#1}\textrangle} |
| 25 |
\newcommand*{\marg}[1]{\texttt{\{}\meta{#1}\texttt{\}}} |
| 26 |
\newcommand*{\oarg}[1]{\texttt{[}\meta{#1}\texttt{]}} |
| 27 |
|
| 28 |
\addtokomafont{title}{\rmfamily} |
| 29 |
|
| 30 |
\title{The \pkg{wrapfig} package\thanks{This manual corresponds to \pkg{wrapfig.sty}~v3.6, dated~Jan 31, 2003.}} |
| 31 |
\author{Donald Arseneau\thanks{\mail{[email protected]}}} |
| 32 |
\date{Jan 31, 2003} |
| 33 |
|
| 34 |
|
| 35 |
\begin{document} |
| 36 |
|
| 37 |
\maketitle |
| 38 |
|
| 39 |
\noindent |
| 40 |
\pkg{Wrapfig.sty} provides the environments \env{wrapfigure} and \env{wraptable} for |
| 41 |
typesetting a narrow float at the edge of the text, and making the text |
| 42 |
wrap around it. The \env{wrapfigure} and \env{wraptable} environments interact |
| 43 |
properly with the \cmd{\caption} command to produce proper numbering, but |
| 44 |
they are not regular floats like \env{figure} and \env{table}, so (beware!) they |
| 45 |
may be printed out of sequence with the regular floats. There are four |
| 46 |
parameters for \verb+\begin{wrapfigure}+, two optional and two required, plus |
| 47 |
the text of the figure, with a caption perhaps: |
| 48 |
% |
| 49 |
\begin{quote} |
| 50 |
\verb+\begin{wrapfigure}[12]{r}[34pt]{5cm}+ \meta{figure} \verb+\end{wrapfigure}+\\ |
| 51 |
\begin{tikzpicture} |
| 52 |
\node (number) at (0mm, 0mm) {\oarg{number of narrow lines}}; |
| 53 |
\node (placement) at (36mm, 0mm) {\marg{placement}}; |
| 54 |
\node (overhang) at (60mm, 0mm) {\oarg{overhang}}; |
| 55 |
\node (width) at (81mm, 0mm) {\marg{width}}; |
| 56 |
\begin{scope}[->] |
| 57 |
\draw (number) -- (16mm, 17mm); |
| 58 |
\draw (placement) -- (24mm, 17mm); |
| 59 |
\draw (overhang) -- (35mm, 17mm); |
| 60 |
\draw (width) -- (47mm, 17mm); |
| 61 |
\end{scope} |
| 62 |
\end{tikzpicture} |
| 63 |
\end{quote} |
| 64 |
|
| 65 |
|
| 66 |
Some idiosyncrasies: |
| 67 |
% |
| 68 |
\begin{itemize} |
| 69 |
\item You must not specify a \env{wrapfigure} in any type of list environment or |
| 70 |
or immediately before or immediately after one. It is OK to follow |
| 71 |
a list if there is a blank line (\cs{par}) in between. |
| 72 |
|
| 73 |
\item If you put a \env{wrapfigure} in a \env{parbox} or a \env{minipage}, or any other type |
| 74 |
of grouping, the text wrapping should end before the group does. |
| 75 |
|
| 76 |
\item It does work in two-column format, but are your figures that small? |
| 77 |
|
| 78 |
\item It may be out of sequence with regular floats. |
| 79 |
|
| 80 |
\item The hlines that may be printed above and below floats are ignored; |
| 81 |
you must insert them manually if desired. |
| 82 |
|
| 83 |
\item \cmd{\linewidth} is now adjusted within the wrapped text, but since it |
| 84 |
can only be set for whole paragraphs at a time, it will persist with |
| 85 |
the wrong value after the wrapping, until the paragraph is finished. |
| 86 |
\end{itemize} |
| 87 |
|
| 88 |
New wrapping environments may be added when new float types are defined |
| 89 |
(using \cls{memoir.cls}, \pkg{float.sty}, or \pkg{ccaption.sty}). Any wrapping environment, |
| 90 |
\env{wrapfigure}, \env{wraptable}, or something else may be invoked using the |
| 91 |
\env{wrapfloat} environment, as in \verb+\begin{wrapfloat}{figure}{O}{5cm}+. |
| 92 |
|
| 93 |
To use \pkg{float.sty} properly, load package \pkg{float} before \pkg{wrapfig}, |
| 94 |
and declare any new float types after loading both. Likewise for |
| 95 |
\pkg{ccaption.sty} and \cmd{\newfloatlist} and \pkg{memoir.cls} and its \cmd{\newfloat}. |
| 96 |
|
| 97 |
|
| 98 |
\section{Placement and Floating} |
| 99 |
|
| 100 |
Parameter \verb+#2+ (required) is the figure placement code, but the valid |
| 101 |
codes are different from regular figures. They come in pairs: an |
| 102 |
uppercase version which allows the figure to float, and a lowercase |
| 103 |
version that puts the figure ``exactly here''. |
| 104 |
% |
| 105 |
\begin{quote} |
| 106 |
\begin{tabular}{*{2}{>{\ttfamily}l}!{--}l} |
| 107 |
r & R & the right side of the text \\ |
| 108 |
l & L & the left side of the text \\ |
| 109 |
i & I & the inside edge--near the binding (if \opt{[twoside]} document) \\ |
| 110 |
o & O & the outside edge--far from the binding |
| 111 |
\end{tabular} |
| 112 |
\end{quote} |
| 113 |
% |
| 114 |
You should specify one code only, not a list. The figure or table must |
| 115 |
be on one side or the other; it cannot be in the middle with text on |
| 116 |
both sides. The \texttt{i} and \texttt{o} options refer to the inside and outside of |
| 117 |
the whole page, not individual columns. |
| 118 |
|
| 119 |
The ability to float is somewhat restricted, and you will get best results |
| 120 |
by giving exact manual placement, but floating is more convenient while |
| 121 |
revising the document. Any changes to the formatting can ruin your manual |
| 122 |
positioning so you should adjust the placement just before printing a |
| 123 |
final copy. Here are some tips for good placement: |
| 124 |
% |
| 125 |
\begin{itemize} |
| 126 |
\item The environment should be placed so as to not run over a page break. |
| 127 |
|
| 128 |
\item The environment must not be placed in special places like lists. |
| 129 |
|
| 130 |
\item For esthetic reasons, only plain text should wrap around the figure. |
| 131 |
Section titles and big equations look bad; lists are bad if the figure |
| 132 |
is on the left. (All these function properly, they just don't look |
| 133 |
very good.) Small equations look fine. |
| 134 |
|
| 135 |
\item It is convenient to begin the environment between paragraphs, but if |
| 136 |
you want placement in the middle of a paragraph, you must put the |
| 137 |
environment between two words where there is a natural line break. |
| 138 |
\end{itemize} |
| 139 |
|
| 140 |
When floating, \LaTeX\ tries to apply these rules. More specifically, |
| 141 |
a floated wrapping environment will only begin\dots |
| 142 |
% |
| 143 |
\begin{itemize} |
| 144 |
\item at the beginning of a paragraph, |
| 145 |
|
| 146 |
\item when there is enough room on the page, or it is possible to go on |
| 147 |
the next page, |
| 148 |
|
| 149 |
\item if the `paragraph' is not in a section title or a list, |
| 150 |
|
| 151 |
\item if the paragraph is not wrapping around another figure, |
| 152 |
|
| 153 |
\item in the main text (not in a \env{minipage} etc.) |
| 154 |
\end{itemize} |
| 155 |
|
| 156 |
It is possible that a non-floating \env{wrapfigure} will be forced to float |
| 157 |
when an earlier one is still being processed. A warning will be written |
| 158 |
in that case. You can have more information about the floating process |
| 159 |
written to the log file by specifying \verb+\usepackage[verbose]{wrapfig}+. |
| 160 |
|
| 161 |
If there is a lot of flexibility on a page, a floating \env{wrapfigure} may |
| 162 |
be placed badly; you must turn to manual placement. A rare problem is |
| 163 |
that floats and footnotes specified within the wrapping text can also |
| 164 |
cause poor placement and bad formatting. |
| 165 |
|
| 166 |
|
| 167 |
\section{Sizing and optional overhang} |
| 168 |
|
| 169 |
Parameter \verb+#4+ (the second required parameter) is the width of the figure |
| 170 |
or table. Given the way that \LaTeX\ puts just about everything into boxes |
| 171 |
with the current line-width, the width parameter will take precedence over |
| 172 |
whatever natural width the figure has. In particular, the caption is always |
| 173 |
typeset with the specified width. If the figure is wider than the space |
| 174 |
allotted, you will get an ``overfull box'' warning. |
| 175 |
|
| 176 |
However, if you specify a width of \emph{zero} (\texttt{0pt}), the actual width of |
| 177 |
the figure will determine the wrapping width. A following \cmd{\caption} |
| 178 |
should have the same width as the figure, but it might fail badly; it |
| 179 |
is safer to specify a width when you use a caption. |
| 180 |
|
| 181 |
\LaTeX\ will wrap surrounding text around the figure, leaving a gap of |
| 182 |
\cmd{\intextsep} at the top and bottom, and \cmd{\columsep} at the side, by |
| 183 |
producing a series of shortened text lines beside the figure. The |
| 184 |
indentation (shortening) of the text is the figure width plus \cmd{\columnsep} |
| 185 |
minus overhang (if any; see below). |
| 186 |
|
| 187 |
\LaTeX\ calculates the number of short lines needed based on the height |
| 188 |
of the figure and the length \cmd{\intextsep}. You can override this guess |
| 189 |
by giving the first optional argument (parameter \verb+#1+) specifying the |
| 190 |
number of shortened lines (counting each displayed equation as 3~lines). |
| 191 |
This is particularly useful when the surrounding text contains extra |
| 192 |
vertical spacing that is not accounted for automatically. |
| 193 |
|
| 194 |
The second optional parameter (\verb+#3+) tells how much the figure should |
| 195 |
hang out into the margin. The default overhang is given by the length |
| 196 |
\cmd{\wrapoverhang}, which is \texttt{0pt} normally but can be changed using |
| 197 |
\cmd{\setlength}. For example, to have all wrapfigures use the space |
| 198 |
reserved for marginal notes, |
| 199 |
% |
| 200 |
\begin{verbatim} |
| 201 |
\setlength{\wrapoverhang}{\marginparwidth} |
| 202 |
\addtolength{\wrapoverhang}{\marginparsep} |
| 203 |
\end{verbatim} |
| 204 |
|
| 205 |
When you do specify the overhang explicitly for a particular figure, you |
| 206 |
can use a special unit called \cmd{\width} meaning the width of the figure. |
| 207 |
For example, \verb+[0.5\width]+ makes the center of the figure sit on the |
| 208 |
edge of the text, and \verb+[\width]+ puts the figure entirely in the margin |
| 209 |
(and the adjacent text is indented by just \cmd{\columnsep}). This \cmd{\width} |
| 210 |
is the actual width of the \env{wrapfigure}, which may be greater than the |
| 211 |
declared width. |
| 212 |
|
| 213 |
|
| 214 |
\section{Some Random Implementation Notes} |
| 215 |
|
| 216 |
Unfortunately, \LaTeX's system of setting \cmd{\everypar} and \cs{par} is |
| 217 |
unable to coexist peacefully with a wrapping environment, so I was |
| 218 |
forced to subvert the \cmd{\@setpar} mechanism and \cmd{\everypar}. (\cmd{\everypar} |
| 219 |
is already subverted once by NFSS.) |
| 220 |
|
| 221 |
When checking the room left on the page, remember that if there is less |
| 222 |
than \cmd{\baselineskip} the new paragraph will begin on the next page, even |
| 223 |
if there is no page stretch. If non-floating, I force a bad page break |
| 224 |
rather than have the figure hang into the bottom margin. |
| 225 |
|
| 226 |
Here are notes on various variables and some macros; what info they |
| 227 |
store and how they are used. |
| 228 |
% |
| 229 |
\begin{description} |
| 230 |
\item[\cmd{\WF@wli}] number-of-wrapped-lines parameter, saved for start of wrapping. |
| 231 |
Set globally by \cmd{\WF@wr} (set empty if no optional parameter given). |
| 232 |
The floating mechanism ignores this and uses the real size. |
| 233 |
|
| 234 |
\item[\cmd{\WF@ovh}] margin overhang set globally by \cmd{\WF@rapt}, saved until placing |
| 235 |
figure (but not reset). Actually, the setting is very tricky so that |
| 236 |
the expected values are used when a figure floats. First, the expression |
| 237 |
is saved without evaluation by \cmd{\WF@rapt} (\verb+\begin{wrapfigure}+) because |
| 238 |
\cmd{\width} is still unknown. Soon after that, \cmd{\endwrapfigure} executes |
| 239 |
\cmd{\WF@ovh} to evaluate the overhang and save the result (so that changes |
| 240 |
to \cmd{\wrapoverhang} while this figure is floating won't affect this |
| 241 |
figure). Finally, it is used by \cmd{\WF@putfigmaybe} when printing the fig. |
| 242 |
|
| 243 |
\item[\cmd{\WF@place}] a macro that is used as a number, giving the placement code. |
| 244 |
It might start out as \texttt{\textasciigrave I} and later be converted to \texttt{114} (r). |
| 245 |
|
| 246 |
\item[\cmd{\WF@box}] tested for void at \verb+\begin{wrapfigure}+, to avoid collisions, % \end{wrapfigure} |
| 247 |
by \cmd{\everypar} to do floating, and by \cmd{\WF@finale} before resetting |
| 248 |
\cmd{\everypar}. Voided globally when used by \cmd{\WF@putfigmaybe} (or by |
| 249 |
\cmd{\WF@wr} if an old figure must be dumped prematurely). |
| 250 |
|
| 251 |
\item[\cs{par}] test if it is \cmd{\@@par} by \verb+\begin{wrapfigure}+ and \cmd{\WF@floathand} % \end{wrapfigure} |
| 252 |
to float past special environments. It is set to \cmd{\@par} (\cmd{\WF@mypar}) |
| 253 |
by \cmd{\WF@startwrapping}, and restored by an end-group (bad!)\ or by |
| 254 |
\cmd{\WF@finale} (good). It is protected from change by redefining |
| 255 |
\cmd{\@setpar}. |
| 256 |
|
| 257 |
\item[\cmd{\parshape}] let to \cmd{\WF@fudgeparshape} by \cmd{\WF@startwrapping}, so lists |
| 258 |
will continue wrapping; \cmd{\@@parshape} preserves the real \cmd{\parshape} |
| 259 |
command, and it is restored by \cmd{\WF@finale} or \cmd{\@parboxrestore}. |
| 260 |
\cmd{\WF@floathand} and \cmd{\WF@wr} test if old wrapping is still in progress |
| 261 |
with \verb+\ifx\parshape\WF@fudgeparshape+. The value of \cmd{\@@parshape} is |
| 262 |
also tested to float past lists and other wrapping environments. |
| 263 |
|
| 264 |
\item[\cmd{\hangindent}] tested to float past section titles etc. |
| 265 |
|
| 266 |
\item[\cmd{\c@WF@wrappedlines}] $\text{the number of shortened lines} + 1$; set globally by |
| 267 |
\cmd{\WF@start\-wrapping} and decremented by \cs{par} (\cmd{\WF@mypar}). It is $> 1$ |
| 268 |
only when wrapping is incomplete. \cmd{\WF@wraphand}, \cmd{\WF@fudgeparshape}, |
| 269 |
and \cmd{\WF@mypar} test the number for calling \cmd{\WF@finale}. It may get |
| 270 |
stuck at some high value if \cs{par} is restored by an end-group, (and |
| 271 |
wrapping is terminated prematurely) so it is unwise to use this as a |
| 272 |
test for wrapping-complete. |
| 273 |
|
| 274 |
\item[\cmd{\pagetotal}] one of many parameters used to compute floating. When |
| 275 |
putting a \env{wrapfigure} in a \env{parbox}, I assign \verb+\let\pagetotal\maxdimen+ |
| 276 |
(locally!)\ to signal not-top-of-page and no floating. |
| 277 |
|
| 278 |
\item[\cmd{\WF@pspars}] the \cmd{\parshape} parameters as \LaTeX\ sets them for lists |
| 279 |
(\cmd{\WF@fudgepar\-shape}); when wrapping I test it and use it to modify my |
| 280 |
own real params for the paragraph. They are also used when \cmd{\parshape} |
| 281 |
is restored after wrapping. |
| 282 |
|
| 283 |
\item[\cmd{\WF@finale}] is performed by \cs{par} when wrapping should end. However, |
| 284 |
that might happen inside a group (a list especially), so the subverted |
| 285 |
versions of \cs{par}, \cmd{\parshape} etc. will be reinstated when the group |
| 286 |
ends. Thus, they must themselves test $\text{\cmd{\c@WF@wrappedlines}} < 2$ to see |
| 287 |
when wrapping is over, and if so, they should just do \cmd{\WF@finale} again. |
| 288 |
\end{description} |
| 289 |
|
| 290 |
These are the tests to see if a floating \env{wrapfigure} will fit at a particular |
| 291 |
spot. These tests are performed at the beginning of every paragraph after |
| 292 |
the figure, except in lists etc. ($\text{\cmd{\pagegoal}} - \text{\cmd{\pagetotal}}$ is the room |
| 293 |
left on the page.) |
| 294 |
% |
| 295 |
\begin{verbatim} |
| 296 |
> |
| 297 |
room_left := \pagegoal - \pagetotal |
| 298 |
if room_left < 0 then page overfull already: |
| 299 |
put figure (on next page) |
| 300 |
else |
| 301 |
if figure_size > room_left then does not fit |
| 302 |
if max(min_stretch, \pagestretch) + extra > room_left |
| 303 |
then page can stretch until full: |
| 304 |
put figure (at top of next page) |
| 305 |
fi |
| 306 |
else figure fits: put figure |
| 307 |
fi fi |
| 308 |
< |
| 309 |
\end{verbatim} |
| 310 |
|
| 311 |
Even if a \env{wrapfigure} is not floating, it will go through the same logic |
| 312 |
to generate a \cmd{\pagebreak}, and maybe an underfull page, when the current |
| 313 |
page can stretch until full. The \texttt{min\_stretch} depends on whether it is |
| 314 |
floating or not: \verb+.5\baselineskip+ (floating) \verb+2\baselineskip+ (not). The |
| 315 |
\texttt{extra} is \verb+.5\baselineskip+ in either case. These values can be adjusted. |
| 316 |
|
| 317 |
There are some other `magic numbers' for floating that aren't really so |
| 318 |
special, but you must change them together if you change them at all. |
| 319 |
To make floating wrapfigures float less and fit on pages more frequently, |
| 320 |
but not change the number of wrapped lines, decrease the \texttt{1.5} in |
| 321 |
\verb+\global\advance\[email protected]\baselineskip+ and increase the \texttt{1.1} in |
| 322 |
\verb+\advance\[email protected]\baselineskip+ by the same amount (and vice versa). |
| 323 |
To make more (or fewer) wrapped lines for the same size figure, without |
| 324 |
changing the floating, change \texttt{1.1} in \verb+\advance\[email protected]\baselineskip+ |
| 325 |
unilaterally. |
| 326 |
|
| 327 |
\end{document} |