使用 wrapfig 和 lettrine 绘制横跨多个段落的图形

使用 wrapfig 和 lettrine 绘制横跨多个段落的图形

我试图让lettrine它们wrapfig和谐相处。我尝试使用 David Carlisle 给出的答案这里。这是一个例子。抱歉它太长了,但我无法再将其最小化了。(上次我尝试时,它完全混淆了问题,请参阅此问题的早期修订):

梅威瑟:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{blindtext}
\usepackage{wrapfig}
\usepackage{lettrine}
\makeatletter
% code by David Carlisle
% https://tex.stackexchange.com/a/121555/4888
\newdimen\tttaa
\newdimen\tttbb
\def\merge@ps{\afterassignment\merge@ps@\tttbb}
\def\merge@ps@{\afterassignment\merge@ps@@\tttaa}
\def\merge@ps@@{%
\afterassignment\reset@WF@ps\dimen@\WF@ps\valign
\ifnum\count@>\@ne
\advance\count@\m@ne
\expandafter\merge@ps
\fi
}
\def\reset@WF@ps{\afterassignment\reset@WF@ps@\dimen@ii}
\def\reset@WF@ps@#1\valign{%
\edef\new@wf@ps{\new@wf@ps
  \the\dimexpr\dimen@+\tttbb\relax\space
  \the\dimexpr\dimen@ii-\tttbb\relax\space}%
 \def\WF@ps{#1}}
\newcommand\wflettrine[3][]{%
  \setbox\tw@\hbox{\lettrine[#1]{#2}{#3}\global\let\gtmp\L@parshape}%
  \afterassignment\wf@getoffset\count@\gtmp\hoffset
  \setbox\WF@box\hbox{\kern-\dimen@\box\WF@box\kern\dimen@}%
  \noindent\box\tw@
    \def\new@wf@ps{}%
    \afterassignment\merge@ps\count@\gtmp
    \edef\WF@ps{\new@wf@ps\space\WF@ps}%
    \@@parshape\c@WF@wrappedlines\WF@ps\z@\columnwidth}
\def\wf@getoffset{\afterassignment\wf@get@ffset\dimen@}
\def\wf@get@ffset#1\hoffset{}
\makeatother
\usepackage{xparse}
\NewDocumentEnvironment{Env}{m}{%
%
%
\begin{wrapfigure}{r}{.4\textwidth}\includegraphics[width=\linewidth,height=1.15in]{#1}\end{wrapfigure}%
}{}
%\columnsep0pt
\intextsep0pt
\newcounter{mystep}
\NewDocumentCommand{\Step}{m}{%
    \stepcounter{mystep}%
    \wflettrine[nindent=0pt]{\hbox to \baselineskip{\hfill\Alph{mystep}\hfill}}#1\par
}
\begin{document}
\begin{Env}{image}
\Step{This is the first step. It probably will not provide enough of this absolutely meaningless text to completely wrap the figure, but it will be enough to properly showcase the lettrine display.}
\Step{This is a second paragraph of meaningless text. Adding this will produce two warnings in the log file: \textit{Package wrapfig Warning: wrapfigure used inside a conflicting environment on input line 50.} and \textit{Package wrapfig Warning: Stationary wrapfigure forced to float on input line 50.} Both of these are not critical, but a bit of a nuisance nevertheless.}
\Step{This third paragraph will not add any further warnings, but for some reason the text length is slightly too short. Here is another sentence to show this fact a bit better, as the previous sentence was a bit too short to demonstrate this thoroughly enough. That can be fixed by setting \texttt{\textbackslash columnsep} to \texttt{0pt}.}
\Step{If the size of the figure is reduced below \texttt{1.15in}, compiling this throws an error: \texttt{! Missing number, treated as zero.
<to be read again> 
                   \textbackslash valign 
l.54 ...al, but a bit of a nuisance nevertheless.\}}}
\end{Env}
\end{document}

输出: 在此处输入图片描述

我发现有三个问题:

  • 完成包装图的第二段给出了两个警告。不过这可能并不严重。

  • 第三段的行号变短了。如果我设置\columnsep为 ,这个问题就消失了0pt

  • 编译将失败,并显示! 缺失数字,视为零如果图像的高度低于 1.15 英寸。我猜想最后一个会随机出现在包含的图形的各种尺寸下,因为我的真实文档中的图形比这个高得多。如果我不设置\intextsep为,这个特定示例就会消失0pt

相关内容