1

I want to put wrapped figures in my report, but I cannot get the text to line up with my figures. Adding white spaces doesn't seem to help -- it just moves the picture down along with the text, but it still doesn't line up. I don't like the way this looks. How do I fix this?

Minimal working example:

\subsection{Data processing}
I want to put a wrapped figure below this text. My report isn't actually about penguins, but enjoy this picture of a cute penguin!

\begin{wrapfigure}{l}{0.45\textwidth}
  \centering
    \includegraphics[width=0.43\textwidth]{penguin.jpg}
    \caption{A very, very cute penguin.}
\end{wrapfigure}

\vspace{15pt}
I would like this text I am writing here, to line up with the top of the figure. How do I do it? Adding a white space doesn't seem to help.

This is the output that I get:

enter image description here

Can someone help me to fix this? Thanks!

2
  • Welcome te TeX SX! You can try with something like \raisebox{\baselineskip}{\includegraphics{penguin}}.
    – Bernard
    Commented Jul 9, 2020 at 9:12
  • Thanks for your answer! Unfortunately this didn't work for me :( Commented Jul 9, 2020 at 9:25

2 Answers 2

3

The spacing above and below a wrapfigure is \intextsep, so either

\setlength\intextsep{0pt}

for no separation generally; or for a specific wrapfigure put

\vspace{-\intextsep}

as the first thing inside the wrapfigure.

Oh! There is a tricky complication too. The wrapfigure tries to be (too) smart by leaving off the top \intextsep when it is at the top of a page. The test is unreliable though, so, in practice, the separation is omitted only at the beginning of the document and after a forced page break (like \newpage). If the wrapfigure might be put in one of those places, \vspace{-\intextsep} may cause the image to intrude into the top margin. If that happens, it will be better to set \intextsep = 0pt, perhaps locally.

1
  • Thanks for your answer and for the explanation! It helps me understand better. I'll definitely try this, it looks more elegant than a negative vspace! Commented Jul 10, 2020 at 22:21
0

Update -- I fixed it by adding a negative \vspace before the \includegraphics. I also added it before \caption to place the caption closer to the picture.

\subsection{Data processing}
\begin{wrapfigure}{r}{0.45\textwidth}
  \centering
  \vspace{-\baselineskip}
    \includegraphics[width=0.43\textwidth]{penguin.jpg}
    \vspace{-8pt}
  \caption{A very, very cute penguin.}
\end{wrapfigure}
1
  • 1
    Ah good. The space above a caption is \abovecaptionskip (generally). Also, \intextsep applies to floats that take the [h] here positioning. Commented Jul 9, 2020 at 10:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .