serhii.net

In the middle of the desert you can say anything you want

05 Dec 2023

Latex floating figures with wrapfig

First paper I write with ONE column, which required a change to my usual image inclusion process.

Generally I’d do:

\begin{figure}[t]
    \includegraphics[width=0.4\linewidth]{images/mypic}
   \caption{My caption}
   \label{fig:mylabel}
\end{figure}

Looking into Overleaf documentation about Inserting Images, found out about wrapfig. Examples from there:

\usepackage{wrapfig}
% ...
\begin{wrapfigure}{L}{0.25\textwidth}
    \centering
    \includegraphics[width=0.25\textwidth]{contour}
\end{wrapfigure}

The magic is:

\begin{wrapfigure}[lineheight]{position}{width}
  ...
\end{wrapfigure}

position for my purposes is lL/rR. Uppercase version allows the figure to float, lowercase means exactly here (a la h in figure)

The first argument lineheight is how many lines should the picture used. Has to be determined later, but gets rid of the large amount of whitespace that sometimes appears under it.

Also — doesn’t like tops/bottoms of pages, section titles, and enums, and creates absolutely ugly results. This really matters.

Includegraphics positions

As a bonus, position options from includegraphics, stolen from Overleaf and converted to table by ChatGPT:

Parameter Position
h Place the float here, i.e., approximately at the same point in the source text
t Position at the top of the page
b Position at the bottom of the page
p Put on a special page for floats only
! Override internal parameters LaTeX uses for determining “good” float positions
H Places the float at precisely the location in the LATEX code
Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus