图片文字与正文基线如何对齐?

图片文字与正文基线如何对齐?

以下代码将正文环绕在图片及其附带文本周围。通过这种方式设置(使用 s \vfill),图片和文本在凹槽中垂直居中。

我想要实现的是将图片下方的文本与基线网格对齐(通过降低两者)。如果我省略\vfill第三个参数中的最后一个\figflow,文本设置得太低了。

资源:我正在使用 XeTeX(包含图片),图流灰色盒子.png和背景网格取自这个答案

\newbox\gridbox
\setbox\gridbox\line{%
  \special{color push rgb .8 .8 1}%
  \vrule height\baselineskip width0pt \hrulefill
  \special{color pop}}
\def\grid{\vtop to0pt{\hrule height0pt\kern-\dimexpr\baselineskip-\topskip\topskip=10pt\relax
    \vbox to\dimexpr\vsize+2pt\relax{\leaders\copy\gridbox\vfil}\vss}}
\def\pagebody{\vbox to\vsize{\boxmaxdepth=\maxdepth \grid\pagecontents}}

\input figflow
\parskip=0pt \frenchspacing \raggedbottom
\font\smallrm=cmr8

\def\includegraphics#1#2#3#4{
{\parfillskip=0pt\par}\dimen0=#1
\dimen1=#2
\advance\dimen0 by 1pc
\setbox0=\vbox to #2{\hsize=#1
\XeTeXpicfile #3 width #1 height #2}
\setbox1=\vbox{\hsize=#1{\noindent\it #4\par}}
\advance\dimen1 by \ht1
\divide\dimen1 by \baselineskip
\multiply\dimen1 by \baselineskip
\advance\dimen1 by \baselineskip
\setbox2=\vbox to \dimen1{\vfil\box0\vskip2mm\box1}
\figflow{\dimen0}{\dimen1}{\vfill\box2\vfill}\noindent\ignorespaces}

\noindent
A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objective-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes---in an
upwardly compatible manner---a variety of important
problems with or lacun\ae\ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more.%
\includegraphics{7cm}{7cm}{greybox.png}{Lorem ipsum dolor sit
amet, consectetur adipiscing elit. Donec a diam lectus.}
Especially pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages can
optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.

A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objective-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes---in an
upwardly compatible manner---a variety of important
problems with or lacun\ae\ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more. Especially
pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages can
optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.
\bye

更新:

情况下,其中\baselineskip,图下文本的字体大小与正文相同,我设法通过将行更改\figflow为来对齐基线

\figflow{\dimen0}{\dimen1}{\vfill\box2\vskip0pt}\noindent\ignorespaces}

为什么插入一个空的会\vskip起作用?请注意,它不适用于其他字体大小,也不适用于其他\baselineskips,即使\strut在框 1 内的组内或组外插入 s 时也不行。

更新2:

感谢 wipet 的回答,我又创建了另一个 MWE,它有一个不太常见的情况:当图片和标题应该位于页面的右下角(或左下角)时:

\newbox\gridbox
\setbox\gridbox\line{%
  \special{color push rgb .8 .8 1}%
  \vrule height\baselineskip width0pt \hrulefill
  \special{color pop}}
\def\grid{\vtop to0pt{\hrule height0pt\kern-\dimexpr\baselineskip-\topskip\topskip=10pt\relax
    \vbox to\dimexpr\vsize+2pt\relax{\leaders\copy\gridbox\vfil}\vss}}
\def\pagebody{\vbox to\vsize{\boxmaxdepth=\maxdepth \grid\pagecontents}}

\input figflow
\parskip=0pt \frenchspacing \raggedbottom
\font\smallrm=cmr8

\def\includegraphics#1#2#3#4{%
   {\parfillskip=0pt\par}
   \dimen0=#1 \ifdim#1<0pt \dimen0=-\dimen0 \fi
   \dimen1=#2 
   \dimen2=#1 \advance\dimen2 by \ifdim#1<0pt-\fi 1pc
   \setbox0=\vbox {\XeTeXpicfile #3 width\dimen0 height #2}
   \setbox1=\vbox{\hsize=\dimen0 \baselineskip=9.5pt\noindent\smallrm #4\par} 
   \advance\dimen1 by \ht1
   \divide\dimen1 by \baselineskip
   \multiply\dimen1 by \baselineskip
   \advance\dimen1 by 1\baselineskip
   \setbox2=\vbox to\dimen1{\vss\box0\vskip2mm\box1}
   \figflow{\dimen2}{\dimen1}{}%
   \line{\ifdim#1<0pt\hfill\fi\vtop to0pt{\kern0pt\box2\vss}\hfil}
   \nobreak\vskip-\baselineskip
   \noindent\ignorespaces}

\noindent
A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objective-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes---in an
upwardly compatible manner---a variety of important
problems with or lacun\ae\ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more.
Especially pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages can
optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.

A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objective-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes---in an
upwardly compatible manner---a variety of important
problems with or lacun\ae\ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more. Especially
pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages can
optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.

A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objective-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes---in an
upwardly compatible manner---a variety of important
problems with or lacun\ae\ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more. Especially
pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages%
\includegraphics{-7cm}{7cm}{greybox.png}{Lorem ipsum dolor sit
amet, consectetur adipiscing elit. Donec a diam lectus.}
can optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.

A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objective-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes---in an
upwardly compatible manner---a variety of important
problems with or lacun\ae\ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more. Especially
pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages can
optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.
\bye

问题是(我认为)在某个地方插入了 ,而使用宏末尾\baselineskip的 可以撤消该操作。这会导致整张图片和图片旁边的文本出现在下一页。当将调用移到上一行( 之前)时,图片会出现在第一页,但图片和标题文本下方会有一行正文。\vskip-\baselineskip\baselineskip\includegraphicsEspecially …

更新 3:

在 figflow.tex 中插入图片时,页面弹出。我\nobreak在某个位置(标记为^^^)添加了一个,弹出就消失了:

% FIGFLOW:  plain TEX macro by Ian Hutchinson, 21 Oct 95.
% Copyright 1995 Ian Hutchinson.
% You may freely use, modify, and/or distribute this file, without limitation.
% Make text flow round figure.
% Usage: \figflow{<width>}{<height>}{<[Figure+][Caption]>}
% at start of new paragraph. Figure top starts at insert.
% #1 figure width dimen. If negative, fig on right, else left.
% #2 figure height (including caption) dimen. (E.g.: 4 truein)
% #3 \special for figure if desired, then \vfill caption. (Both optional).
% Example: figflow{4 truein}{5 truein}{\epsfbox{figure.ps}\vfill Figure 1.}
% User is responsible for the figure fitting within the space defined.
% If figure won't fit on page, it is moved over the page break.
% If a new figflow starts before the old one is finished, a message is given
% and the second figure is skipped. Fix manually.
% Does not work for Latex.

\newdimen\pageremains\newdimen\pdepth
\newdimen\figwidth
\newdimen\figheight
\newcount\figlines
\newcount\flevel

\def\figflow#1#2#3{
\ifnum\flevel>0
\message{******Figure collision. Ignoring second figure.******}
\else
\figwidth=#1
\figheight=#2
\def\contents{#3}
% Put figure contents in an appropriate box.
\def\figure{\let\temp=\par \let\par=\plainpar
  \line{\overfullrule=0pt%  Avoid black box.
   \ifdim \figwidth<0pt \hsize=-\figwidth \hss\else \hsize=\figwidth\fi
   \advance \hsize by -10pt% Give a little extra hspace.
   \vbox to \figheight{\vfil\noindent\contents}
   \ifdim \figwidth>0pt \hss\fi
  }\nobreak\vskip-\figheight
%  ^^^^^^^^ inserted by MK
  \let\par=\temp%
}
% […] remainder of file is the same

现在存在的唯一问题是页面上的最后两行被移到了下一页(包括缩短)。我认为这与 和 有关\widowpenalty\clubpenalty但修改这些变量并不能解决问题。

我们也赞赏针对上述问题的任何更好的解决方案。

更新 4:

\nobreak\̺在第一页正文的最后一个单词后面手动添加一个(即,在 之后a variety of important)确实解决了更新 3 中提到的问题,但现在此时也禁止换行,导致行(太)紧和不必要的连字符。如何解决这个问题,当然,如何自动化?

更新 5:

在进行某种压力测试时,我遇到了另一个问题。我添加了两个宏\toppicture和,\midpicture分别在开始之前添加了一个\eject或一个(请不要因为这段代码太长而回避它,其中大部分是虚拟文本):\par\includegraphics

\newbox\gridbox
\setbox\gridbox\line{%
  \special{color push rgb .8 .8 1}%
  \vrule height\baselineskip width0pt \hrulefill
  \special{color pop}}
\def\grid{\vtop to0pt{\hrule height0pt\kern-\dimexpr\baselineskip-\topskip\topskip=10pt\relax
    \vbox to\dimexpr\vsize+2pt\relax{\leaders\copy\gridbox\vfil}\vss}}
\def\pagebody{\vbox to\vsize{\boxmaxdepth=\maxdepth \grid\pagecontents}}

\input figflow
\parskip=0pt \frenchspacing \raggedbottom
\widowpenalty=10000 \clubpenalty=10000
\font\smallrm=cmr8

%\toppicture params:
%  #1 <dimen>  width of picture
%  #2 <dimen>  height of picture
%  #3 <string> file name
%  #4 <string> caption text
\def\toppicture#1#2#3#4{%
   {\parfillskip=0pt\par}\eject%
   \includegraphics{#1}{#2}{#3}{#4}
}

%\midpicture params:
%  #1 <dimen>  width of picture
%  #2 <dimen>  height of picture
%  #3 <string> file name
%  #4 <string> caption text
\def\midpicture#1#2#3#4{%
   {\parfillskip=0pt\par}
   \includegraphics{#1}{#2}{#3}{#4}
}

\def\includegraphics#1#2#3#4{%
   \dimen0=#1 \ifdim#1<0pt \dimen0=-\dimen0 \fi
   \dimen2=#2 
   \dimen4=#1 \advance\dimen4 by \ifdim#1<0pt-\fi 1pc
   \setbox0=\vbox {\XeTeXpicfile #3 width\dimen0 height #2}
   \setbox2=\vbox{\hsize=\dimen0 \baselineskip=9.5pt\noindent\smallrm #4\par} 
   \advance\dimen2 by \ht2
   \divide\dimen2 by \baselineskip
   \multiply\dimen2 by \baselineskip
   \advance\dimen2 by \baselineskip
   \setbox4=\vbox to\dimen2{\vss\box0\vskip2mm\box2}
   \figflow{\dimen4}{\dimen2}{}
   \line{\ifdim#1<0pt\hfill\fi\vtop to0pt{\kern0pt\box4\vss}\hfil}
   \nobreak\vskip-\baselineskip
   \noindent\ignorespaces}

\noindent
A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objective-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes---in an
upwardly compatible manner---a variety of important
problems with or lacun\ae\ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more.
Especially pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages can
optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.

A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objective-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes---in an
upwardly compatible manner---a variety of important
problems with or lacun\ae\ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more. Especially
pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages can
optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.

A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objective-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes---in an
upwardly compatible manner---a variety of important
problems with or lacun\ae\ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more.
Especially pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages
\midpicture{-7cm}{7cm}{greybox.png}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.}
can optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.

A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objective-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes---in an
upwardly compatible manner---a variety of important
problems with or lacun\ae\ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode,
%\midpicture{7cm}{7cm}{greybox.png}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.}
namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more. 
These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more. Especially
pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages can
optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI 
\midpicture{7cm}{7cm}{greybox.png}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.}
or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.

%\toppicture{7cm}{7cm}{greybox.png}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.}
A work in progress, {\tt JSBox} is a self-contained
library---written in portable C---that instantiates sandbox-able,
\TeX-language interpreters within the memory space
of any C, Objective-C, or C++ 32- or 64-bit client
program. Built and documented anew, {\tt JSBox}
is faithful to the \TeX\ language's primitives,
syntax, typesetting algorithms, measurements, data
structures, and speed. At the same time, it fixes---in an
upwardly compatible manner---a variety of important %\nobreak\
problems with or lacun\ae\ in the current \TeX\ engine's
implementation. These include integral support for
21-bit Unicode, namespaces, OpenType font tables
and metrics, job-specific 8-bit to 21-bit Unicode
mapping, run-time settable compatibility levels,
full 32-bit fixed-point math, and more. Especially
pertinent to interactive applications---such as an
eBook reader---is that all of a document's pages can
optionally be kept as \TeX\ data structures in memory
after a job is done, with direct random access of any
requested page exported to the client program's screen
without file I/O or DVI or PDF conversion if unneeded.
Tracing (including recursive expansion, re-tracing
interrupted commands, alignments, math, etc.) and
all error messages have been significantly improved
over what \TeX\ does. The author will demo what
{\tt JSBox} can do now, and discuss what it
could do in the future.
\bye

首先,注释掉第二个\midpicture(应该在第 169 行)并运行 XeTeX。不管怎样,我现在可以省略我在更新 3(添加到\nobreakfigflow.tex)和更新 4(添加\nobreak\到源副本)中所做的更改,并且所有内容都排版正常。这很奇怪,因为据我所知,我没有更改任何其他内容。文本在图片和图片标题周围正确流动。

请取消\midpicture注释刚刚注释掉的调用,然后再次运行 TeX。现在它抱怨在}之前插入\endgroup。这听起来很奇怪。这里发生了什么?

第三,再次注释掉该行并取消注释\midpicture第 149 行。现在 figflow.tex 会抱怨图形冲突,可能是因为它没有处理完第一张图片旁边的线条,尽管我是\midpicture在行中的最后一个单词之后调用宏的。这意味着不能将两张图片直接放在彼此下方(它们不应该发生冲突)。如何避免这种冲突?

第四,再次注释掉第 149 行,并取消注释\toppicture第 178 行上唯一的 。奇怪的是,这一次 TeX 不会像\figflow取消注释第 169 行时那样在第二次调用时卡住。结果是两个排版正确的页面和一个左上角有图片的新页面。只是现在所有内容(正文、图片和图片标题)都略微偏离了网格。这里出了什么问题?

答案1

我建议仅使用\figflow为图片创建适当的空间并将图片置于我们的控制之下。

\def\includegraphics#1#2#3#4{
{\parfillskip=0pt\par}\dimen0=#1
\dimen1=#2
\advance\dimen0 by 1pc
\setbox0=\vbox to #2{\hsize=#1
\XeTeXpicfile #3 width #1 height #2}
\setbox1=\vbox{\hsize=#1{\noindent\it #4\par}}
\advance\dimen1 by \ht1
\divide\dimen1 by \baselineskip
\multiply\dimen1 by \baselineskip
\advance\dimen1 by 1\baselineskip
\setbox2=\vbox to \dimen1{\vfil\box0\vskip2mm\box1}
   % PO changes in OP's code: 
  \figflow{\dimen0}{\dimen1}{}%
  \vtop to0pt{\kern0pt\box2\vss}\nobreak\vskip-\baselineskip
\noindent\ignorespaces}

如果您设置\kern-\baselineskip\kern0pt内部\vtop,则图片将放置在上一行。

编辑:考虑到评论,我添加了代码的第二个版本,其中\baselineskip图片下方文本的 可以是任意的,\includegraphics宏的第一个参数可以是负数。然后\dimen0是此参数的绝对值, 是\dimen2新引入的#1正或负 1pc(根据 的符号添加边距#1)。

\def\includegraphics#1#2#3#4{%
   {\parfillskip=0pt\par}
   \dimen0=#1 \ifdim#1<0pt \dimen0=-\dimen0 \fi
   \dimen1=#2 
   \dimen2=#1 \advance\dimen2 by \ifdim#1<0pt-\fi 1pc
   \setbox0=\vbox {\XeTeXpicfile #3 width\dimen0 height #2}
   \setbox1=\vbox{\hsize=\dimen0 \noindent\it #4\par} 
   \advance\dimen1 by \ht1
   \divide\dimen1 by \baselineskip
   \multiply\dimen1 by \baselineskip
   \advance\dimen1 by 1\baselineskip
   \setbox2=\vbox to\dimen1{\vss\box0\vskip2mm\box1}
   \figflow{\dimen2}{\dimen1}{}%
   \line{\ifdim#1<0pt\hfill\fi\vtop to0pt{\kern0pt\box2\vss}\hfil}
   \nobreak\vskip-\baselineskip
   \noindent\ignorespaces}

编辑2:\oblom考虑到你对问题的更新,我决定你可以尝试我书中的宏TeXbook 纳鲁比(第 236 和 237 页)。本书的完整 PDF 版本可用,但仅提供捷克语。

该宏的名称\oblom源自捷克语单词“围绕某物进行排版”。此宏在下一段(或更多段)中创建白色矩形空间。我的下一个代码使用此宏(但重命名了分隔符词)。此宏的用法是:

\oblom <width> from <linenum1> indent <linenum2>

其中<width>是矩形空间的宽度,<linenum1>是第一个缩进的行号,<linenum2>是缩进的行数。如果<width>为负数,则矩形空间将位于右侧。例如:

\oblom 5cm from 3 indent 5

表示五行从第三行(包括这一行)开始缩进 5cm。前两行不缩进,且为正常宽度。

\oblom必须在段落之间使用,它会影响接下来一个或多个段落的形状。主要优点是您不必在缩进开始的地方精确地停止段落。请注意您之前的示例,您必须这样做,{\parfillskip=0pt\par}这会带来复杂性。

我的下一个代码使用\oblom并定义宏\flowpic

\flowpic from <linenum> width <width> {<picfile>} {<caption>}

例如

\flowpic from 3 width -7cm {greybox.png}
    {Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.}

greybox.png在下一个段落的第三行右侧插入带有给定标题的图片。图片的宽度为 7cm 减 1pc,因为 1pc 是图片和文本之间的边距。您不需要使用 pckage figflow

代码由三部分组成。第一部分是\oblomTeXbook 纳鲁比。该宏计算\parshape参数并使用\parshape。第二部分定义插入具有给定宽度的图片的宏\pic。定义取决于是否使用 XeTeX。第三部分声明\flowpic使用\oblom\pic。如果有足够的空间,flowpic 宏会将图片插入到使用图片的同一页。如果空间不够,flowpic 会将图片插入到下一页,即修改形状的最后段落结束的位置。

\newcount\shapenum \newcount\tempnum \newcount\globpar
\newdimen\ii \newdimen\ww
\newdimen\picwidth  \newbox\picbox
\catcode`\@=11  
\def\oblom #1 from #2 indent #3 {\par \ii=#1 \ww=\hsize
   \ifdim\ii>\z@ \advance\ww by-\ii      
   \else \advance\ww by\ii \ii=\z@ \fi
   \shapenum=1 \tempnum=0 \def\shapelist{}
   \loop \ifnum\shapenum<#2 \edef\shapelist{\shapelist\z@\hsize}
      \advance\shapenum by1 \repeat
   \loop \edef\shapelist{\shapelist\ii\ww}
      \advance\tempnum by1 \ifnum\tempnum<#3 \repeat
   \advance\shapenum by#3 \edef\shapelist{\shapelist\z@\hsize}
   \doshape}  
\catcode`\@=12
\def\doshape{\globpar=0 \def\par{\ifhmode\shapepar\fi}}
\def\shapepar{\prevgraf=\globpar \parshape\shapenum\shapelist
   \endgraf \globpar=\prevgraf
   \ifnum \prevgraf<\shapenum\else \global\let\par=\endgraf \doshapeA \fi}

\ifx\XeTeXpicfile\undefined 
   \def\pic #1{\hbox{\pdfximage width\picwidth {#1}\pdfrefximage\pdflastximage}}
\else
   \def\pic #1{\hbox{\XeTeXpicfile #1 width\picwidth}}
\fi

\def\flowpic from #1 width #2 #3#4{\par
   \dimen0=#2 \ifdim\dimen0<0pt \dimen0=-\dimen0 \fi
   \advance\dimen0 by -1pc %(margin around picture)
   \picwidth=\dimen0
   \setbox0=\vbox{\hsize\dimen0 \pic{#3}\kern 2mm 
                  \emergencystretch=2em \noindent\it #4}
   \dimen0=\ht0 
   \divide\dimen0 by\baselineskip \advance\dimen0 by1sp
   \oblom #2 from #1 indent \dimen0 
   \multiply\dimen0  by\baselineskip
   \setbox\picbox=\vbox to\dimen0{\vss\box0}
   \dimen0=\pagegoal \ifdim\pagegoal=\maxdimen \dimen0=\vsize\fi   
   \advance\dimen0 by-\pagetotal \advance\dimen0 by-#1\baselineskip
   \ifdim\dimen0<0pt 
      \def\doshapeA{\tempnum=\prevgraf \advance\tempnum by-#1 \advance\tempnum by2
         \line{\ifdim#2<0pt \hfill\fi \vbox to0pt{\vss\vtop to0pt{\kern0pt\box\picbox\vss}%
                   \kern\the\tempnum\baselineskip}\hfil}
         \nobreak\vskip-\baselineskip
      }
   \else \def\doshapeA{}
      \line{\ifdim#2<0pt \hfill\fi 
            \vtop to0pt{\kern-2\baselineskip\kern#1\baselineskip\box\picbox\vss}\hfil}
      \nobreak\vskip-\baselineskip
   \fi
}
\parindent=0pt \raggedbottom % we need the grid

此宏的限制是:您不能将图片放置在页面的“边缘”上,即分页符处。只能放置在分页符之前或之后。您不能将两张图片插入一个段落中。下一个 的使用\flowpic只允许在段落之前,即没有上一个 缩进的行处\flowpic。如果您的段落很长,并且需要\flowpic在此处放置两个 ,那么您需要使用已知的技巧 来{\parfillskip=0pt\par}关闭上一个“不可见”的段落。

相关内容