# How do I raise a figure (placed with wrapfig) to be flush with the top of a paragraph?

I am using the wrapfig package to place a figure with text wrapped around it. Here is a minimal example, with a screenshot of the relevant part of the output below:

\documentclass{book}

\usepackage{graphicx}
\usepackage{wrapfig}

\begin{document}

\begin{center}
\textbf{\Large Lorem ipsum}
\end{center}
\vspace{18pt}

\begin{wrapfigure}[15]{r}{0in}
\includegraphics[width=0.4\textwidth]{TestImage.jpg}
\end{wrapfigure}

Lorem ipsum ... ridiculus mus.

\end{document}

Looking at this output, I am not fond of how the figure is placed somewhat down from the top of the first paragraph. What is a minimal solution for raising the figure so that the top edge of the image is flush with the top of this paragraph?

A few clarifying notes: I don't need the solution to find the top of the paragraph automatically -- if I can just raise the image by a manually entered length, that's fine. Also, I'm fine with making this manual adjustment for each image; there's no need to make the change to all such images if that's not convenient.

• Note that wrapfig adds a gap of \intextsep above and below. There are several ways to compensate, such as adding \vskip-\intextsep or using \raisebox{0pt}[\dimexpr \height-\intextsep][\dimexpr \depth-\intextsep]{...}. The location of the baseline is irrelevant; all that matters is the height and depth. – John Kormylo Mar 10 at 0:20

You can set \intextsep:

\documentclass{book}

\usepackage{graphicx}
\usepackage{wrapfig}
\setlength\intextsep{0pt}
\begin{document}

\begin{center}
\textbf{\Large Lorem ipsum}
\end{center}
\vspace{18pt}

\begin{wrapfigure}[15]{r}{0in}
\includegraphics[width=0.4\textwidth]{example-image-duck}
\end{wrapfigure}

Lorem ipsum ... ridiculus mus.

\end{document}

An more manual alternative is to trim the graphic. By adjusting the value, you can move the graphic up and down:

\documentclass{book}

\usepackage{graphicx}
\usepackage{wrapfig}
\begin{document}

\begin{center}
\textbf{\Large Lorem ipsum}
\end{center}
\vspace{18pt}

\begin{wrapfigure}[15]{r}{0in}
\includegraphics[width=0.4\textwidth,trim=0pt 0pt 0pt 30pt]{example-image-duck}
\end{wrapfigure}

Lorem ipsum ... ridiculus mus.

\end{document}
• \includegraphics[clip,width=0.4\textwidth,trim=0pt 0pt 0pt 65pt]{example-image-duck} ? – David Carlisle Mar 9 at 20:08

Since you don't add a caption, it is simpler to use the \InsertBoxR command, from the plain TeX macro package insbox. This command takes 2 mandatory arguments: the number of lines that remain untouched before the object is inserted, and the object itself, and 1 optional argument – yhe number of supplementary dhorter lines, in case TeX makes a wrong calculation of the number of lines that have to be shortened.

In the following code, the image is even above the first line (using a negative 1st argument), and I used a negative optional argument, so there no blank space under the image.

\documentclass{book}

\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage[svgnames]{xcolor}
\usepackage{lipsum}
\input{insbox}
\makeatletter\@InsertBoxMargin =3mm\makeatother

\begin{document}

\begin{center}
\textbf{\Large Lorem ipsum}
\end{center}
\vspace{18pt}

\InsertBoxR{-1}{{\color{YellowGreen}\rule{0.35\textwidth}{0.3\textheight}}}[-2]
\lipsum

\end{document}