2

In this example

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{wrapfig}
\begin{document}

foo \begin{minipage}[t]{.9\linewidth}
              \lipsum[1]
            \end{minipage}

bar  \begin{minipage}[t]{.9\linewidth}
              \begin{wrapfigure}{r}{0pt}
                \includegraphics[width=3cm]{example-image-a}
              \end{wrapfigure}
              \lipsum[2]
            \end{minipage}

\end{document}

the vertical alignment of the first minipage is as requested, the first line of the \lipsum perfectly aligns with the outside foo.

In the second minipage however, the vertical alignment of the text is off. This is because the wrapfigure creates a baseline right at the top of the minipage, such that the location of the baseline of the first actual line is not available any more. This results in aligning the very top of the minipage with the baseline of bar.

Is there any way to either

  1. restore that information

or

  1. force the baseline of the first line to be a specific distance from the top of the minipage such that the minipage can be raised by that specific amount?

1 Answer 1

1

I found a way to do the second option by inserting a strut and adjusting the minipage accordingly. The adjustbox package has everything available that is needed:

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{wrapfig}
\usepackage{calc}
\usepackage{adjustbox}
\newlength{\strutheight}

\begin{document}

  \settoheight{\strutheight}{\strut}

  foo \begin{minipage}[t]{.9\linewidth}
        \lipsum[1]
      \end{minipage}

  bar \begin{adjustbox}{valign=T,raise=\strutheight,minipage={.85\linewidth}}
        \begin{wrapfigure}{r}{0pt}
          \includegraphics[width=3cm]{example-image-a}
        \end{wrapfigure}
        \strut \lipsum[2]
      \end{adjustbox}

\end{document}

You must log in to answer this question.

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