wrapfig——将材料包裹至自然高度

wrapfig——将材料包裹至自然高度

我想使用 将说明性文本(从一句话到多个段落的任何内容)环绕在某些主题文本周围wrapfig。只要说明性文本比主题文本长,代码就会按预期工作。如果主题文本比说明性文本长,则主题文本会覆盖下一段中的文本。换句话说,我希望环绕的材料保持其自然高度。我也尝试过,cutwininsbox没有成功。

\documentclass[11pt]{article}

\usepackage{xparse,wrapfig,lipsum}
\usepackage[margin=1.75in,top=0.5in]{geometry}

%%% =====8><----- %%%

\NewDocumentCommand{\step}{+mm}{%
    \ignorespaces
    \par
    \noindent
    {%%
        \begin{minipage}{\textwidth}
            \begin{wrapfigure}{o}{0pt}
                \parbox[t]{0.4\textwidth}{%
                    \itshape#2
                }%
            \end{wrapfigure}\par
            #1\par
        \end{minipage}
    }%
    \par
    \bigskip
}

\setlength{\intextsep}{0pt}

\begin{document}

\noindent This is the current output:

\bigskip

\step{1 This is a little text. And this is some more bla bla to see just how this works out.}{\lipsum*[3][1-3]}

\step{2 This is a little text. And this is some more bla bla to see just how this works out.}{\lipsum*[3][1-2]}

\step{3 This is a little text. And this is some more bla bla to see just how this works out. This is a little text. And this is some more bla bla to see just how this works out.
This is a little text. And this is some more bla bla to see just how this works out.}{\lipsum*[3][1-2]}

\step{4 This is a little text. And this is some more bla bla to see just how this works out. This is a little text. And this is some more bla bla to see just how this works out.
This is a little text. And this is some more bla bla to see just how this works out.}{\lipsum*[3][1-2]}

\vspace{0.5in}

\noindent This is the desired output, but, hopefully, without the manual intervention:

\bigskip

\step{1 This is a little text. And this is some more bla bla to see just how this works out.}{\lipsum*[3][1-3]}

\vspace{3\baselineskip}

\step{2 This is a little text. And this is some more bla bla to see just how this works out.}{\lipsum*[3][1-2]}

\vspace{2\baselineskip}

\step{3 This is a little text. And this is some more bla bla to see just how this works out. This is a little text. And this is some more bla bla to see just how this works out.
This is a little text. And this is some more bla bla to see just how this works out.}{\lipsum*[3][1-2]}

\step{4 This is a little text. And this is some more bla bla to see just how this works out. This is a little text. And this is some more bla bla to see just how this works out.
This is a little text. And this is some more bla bla to see just how this works out.}{\lipsum*[3][1-2]}

\vfill

\end{document}

wrapfig 示例

答案1

Wrapfig 向计数器提供了WF@wrappedlines剩余需要换行的行数。

\documentclass[11pt]{article}

\usepackage{xparse,wrapfig,lipsum}
\usepackage[margin=1.75in,top=0.5in]{geometry}

%%% =====8><----- %%%

\NewDocumentCommand{\step}{+mm}{%
    \ignorespaces
    \par
    \noindent
    {%%
        \begin{minipage}{\textwidth}
            \begin{wrapfigure}{o}{0pt}
                \parbox[t]{0.4\textwidth}{%
                    \itshape#2
                }%
            \end{wrapfigure}\par
            #1\par
            \loop\ifnum\value{WF@wrappedlines}>1
              \strut\par
            \repeat
        \end{minipage}
    }%
    \par
    \bigskip
}

\setlength{\intextsep}{0pt}

\begin{document}

\noindent This is the current output:

\bigskip

\step{1 This is a little text. And this is some more bla bla to see just how this works out.}{\lipsum*[3][1-3]}

\step{2 This is a little text. And this is some more bla bla to see just how this works out.}{\lipsum*[3][1-2]}

\step{3 This is a little text. And this is some more bla bla to see just how this works out. This is a little text. And this is some more bla bla to see just how this works out.
This is a little text. And this is some more bla bla to see just how this works out.}{\lipsum*[3][1-2]}

\step{4 This is a little text. And this is some more bla bla to see just how this works out. This is a little text. And this is some more bla bla to see just how this works out.
This is a little text. And this is some more bla bla to see just how this works out.}{\lipsum*[3][1-2]}

\end{document}

相关内容