xparse / wrapfigure:\intextsep 在 \NewDocumentEnvironment 中设置时不会影响输出

xparse / wrapfigure:\intextsep 在 \NewDocumentEnvironment 中设置时不会影响输出

对于以下内容,为什么\setlength{\intextsep}{#5}inside\NewDocumentEnvironment{mywrapfigure}对输出没有任何影响,这使我必须\setlength{\intextsep}{0pt}在每次使用 之前在本地使用wrapfigure?例如,image-b不受 的影响\setlength{\intextsep}{#5}

另外,为什么下面的空间image-a比下面的还要窄呢image-c

在此处输入图片描述

\documentclass{exam}
\usepackage{graphbox,wrapfig,duckuments}

\usepackage{xparse}

% https://tex.stackexchange.com/a/266431/2288
\NewDocumentEnvironment{mywrapfigure}{O{}mO{\wrapoverhang}mO{0pt}}{%
    \setlength{\intextsep}{#5}%  <<< has no effect
    \wrapfigure[#1]{#2}[#3]{#4}%
}{%
    \endwrapfigure%
}

\begin{document}
    {% https://tex.stackexchange.com/a/365764/2288
        \setlength\intextsep{0pt}
        \begin{mywrapfigure}{r}{0.3\linewidth}
            \includegraphics[width=\linewidth]{example-image-a}
        \end{mywrapfigure}
        \blindduck[1-2]
    }
    \bigskip
    \begin{questions}
        \begin{minipage}[t][][t]{\linewidth}
            \question
            {% https://tex.stackexchange.com/a/365764/2288
                %\setlength\intextsep{0pt}
                \begin{mywrapfigure}{r}{0.3\linewidth}[0pt]
                    \includegraphics[width=\linewidth]{example-image-b}
                \end{mywrapfigure}
                \blindduck[1-2]
            }
        \end{minipage}
        \bigskip
        \begin{parts}
            \begin{minipage}[t]{\linewidth}
                \part[4]
                {% https://tex.stackexchange.com/a/365764/2288
                    \setlength\intextsep{0pt}
                    \begin{mywrapfigure}{r}{0.3\linewidth}[0pt]
                        \includegraphics[width=\linewidth]{example-image-c}
                    \end{mywrapfigure}
                    \blindduck[1-2]
                }
            \end{minipage}
        \end{parts}
    \end{questions}
\end{document}

更新 1

使用 lualatex 编译以下内容

\documentclass{exam}
\usepackage{graphbox,wrapfig,duckuments,blindtext}

\usepackage{xparse}

\NewDocumentEnvironment{mywrapfigure}{O{}mO{\wrapoverhang}mO{1pt}}{%
    \setlength{\intextsep}{#5}%  <<< has no effect
    \wrapfigure[#1]{#2}[#3]{#4}%
}{%
    \endwrapfigure%
}

\begin{document}
    \begin{mywrapfigure}{r}{0.3\linewidth}
        \includegraphics[width=\linewidth]{example-image-a}
    \end{mywrapfigure}
    \blindduck[1]
    \bigskip
    \begin{questions}
        \begin{minipage}[t]{\dimexpr \linewidth}
            \question%\the\everypar
            \begin{mywrapfigure}{r}{0.3\linewidth}
                \vskip-\baselineskip
                \includegraphics[width=\linewidth]{example-image-b}
            \end{mywrapfigure}
            \blindtext[1]
        \end{minipage}
        \bigskip%\hrule
        \begin{parts}
            \begin{minipage}[t]{\linewidth}
                \part[4]%\the\everypar
                \begin{mywrapfigure}{r}{0.3\linewidth}
                    \vskip-\baselineskip
                    \includegraphics[width=\linewidth]{example-image-c}
                \end{mywrapfigure}
                \blindduck[1]
            \end{minipage}
        \end{parts}
    \end{questions}
\end{document}

我明白了

在此处输入图片描述

答案1

每次将 wrapfigure 紧跟在后面\item(由\question和所用\part),它都会被下推一行。(有趣的是,它\rlap{...}被上推一行。)解决此问题的唯一方法是手动添加\vskip-\baselineskip内部 wrapfigure。它与 无关\intextsep

\documentclass{exam}
\usepackage{graphbox,wrapfig,duckuments}

\usepackage{xparse}

\NewDocumentEnvironment{mywrapfigure}{O{}mO{\wrapoverhang}mO{1pt}}{%
    \setlength{\intextsep}{#5}%  <<< has no effect
    \wrapfigure[#1]{#2}[#3]{#4}%
}{%
    \endwrapfigure%
}

\begin{document}
    \begin{mywrapfigure}{r}{0.3\linewidth}
            \includegraphics[width=\linewidth]{example-image-a}
        \end{mywrapfigure}
        \blindduck[1-2]
    \bigskip
    \begin{questions}
    \begin{minipage}[t]{\dimexpr \linewidth}
           \question%\the\everypar
                \begin{mywrapfigure}{r}{0.3\linewidth}
                    \vskip-\baselineskip
                    \includegraphics[width=\linewidth]{example-image-b}
                \end{mywrapfigure}
                \blindduck[1-2]
        \end{minipage}
        \bigskip%\hrule
        \begin{parts}
            \begin{minipage}[t]{\linewidth}
                \part[4]%\the\everypar
                    \begin{mywrapfigure}{r}{0.3\linewidth}
                        \vskip-\baselineskip
                        \includegraphics[width=\linewidth]{example-image-c}
                    \end{mywrapfigure}
                    \blindduck[1-2]
            \end{minipage}
        \end{parts}
    \end{questions}
\end{document}

更新 1

\WFclear如果在 wrapfigure 完成之前文本用完,则应始终使用。请注意对第二幅图像使用可选参数 [9]。还请注意,它\linewidth会不断变小,从而使图像也变得更小。

\documentclass{exam}
\usepackage{graphbox,wrapfig,duckuments,blindtext}

\usepackage{xparse}

\NewDocumentEnvironment{mywrapfigure}{O{}mO{\wrapoverhang}mO{1pt}}{%
    \setlength{\intextsep}{#5}%  <<< has no effect
    \wrapfigure[#1]{#2}[#3]{#4}%
}{%
    \endwrapfigure%
}

\begin{document}
    \begin{mywrapfigure}{r}{0.3\linewidth}
        \includegraphics[width=\linewidth]{example-image-a}
    \end{mywrapfigure}
There once was a very smart but sadly blind duck. When it was still a small duckling it was renowned for
its good vision. But sadly as the duck grew older it caught a sickness which caused its eyesight to worsen.
It became so bad, that the duck couldn't read the notes it once took containing much of inline math. Only
displayed equations remained legible. That annoyed the smart duck, as it wasn't able to do its research any
longer. It called for its underduckling and said:  Go, find me the best eye ducktor there is. He shall heal
me from my disease!"
    %\blindduck[1]\par
    \bigskip
    \WFclear
    \begin{questions}
        \begin{minipage}[t]{\dimexpr \linewidth}
            \question
            \begin{mywrapfigure}[9]{r}{0.3\linewidth}
                \vskip-\baselineskip
                \includegraphics[width=\linewidth]{example-image-b}
            \end{mywrapfigure}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis
facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent
imperdiet mi nec ante. Donec ullamcorper, felis non sodales commodo,
lectus velit ultrices augue, a dignissim nibh lectus placerat pede. 
Vivamus nunc nunc, molestie ut, ultricies vel, semper in, velit. Ut porttitor.
Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer adipiscing 
elit. Duis fringilla tristique neque. Sed interdum libero ut metus.
Pellentesque placerat. Nam rutrum augue a leo. Morbi sed elit sit
amet ante lobortis sollicitudin. Praesent blandit blandit mauris. Praesent lectus tellus, aliquet aliquam,
luctus a, egestas a, turpis. Mauris lacinia lorem sit amet ipsum. Nunc quis urna dictum turpis accumsan
            %\blindtext[1]
        \end{minipage}
        \bigskip%\hrule
        \begin{parts}
            \begin{minipage}[t]{\linewidth}
                \part[4]%\the\everypar
                \begin{mywrapfigure}{r}{0.3\linewidth}
                    \vskip-\baselineskip
                    \includegraphics[width=\linewidth]{example-image-c}
                \end{mywrapfigure}
There once was a very smart but sadly blind duck. When it was still a small duckling it was renowned for
its good vision. But sadly as the duck grew older it caught a sickness which caused its eyesight to worsen.
It became so bad, that the duck couldn't read the notes it once took containing much of inline math. Only
displayed equations remained legible. That annoyed the smart duck, as it wasn't able to do its research any
longer. It called for its underduckling and said:  Go, find me the best eye ducktor there is. He shall heal
me from my disease!"
\WFclear
            \end{minipage}
        \end{parts}
    \end{questions}
\end{document}

相关内容