MWE 中的线条间距不足,使用\hbox
两个框填充\vtop
。
\parindent=0pt
\newdimen\linewidth
\linewidth=4in
\newdimen\colsep
\colsep=1em
\newdimen\colwidth
\colwidth=0.5\linewidth
\advance\colwidth by -1\colsep
\def\twocols#1#2{%
\hbox to \linewidth{%
\vtop{\hsize=\colwidth
\hangindent=1em \hangafter=1 #1\par}\hfill
\vtop{\hsize=\colwidth
\hangindent=1em \hangafter=1 #2\par}\hss
}\par
}
\twocols
{This is a very long line that will run over}
{What is wrong with the spacing?}
\twocols
{What is wrong with the spacing?}
{This is a very long line that will run over}
\bye
答案1
如果你打开日志记录,你会看到可怕的
..\glue(\lineskip) 1.0
vtop 框具有较大的深度,并且下一个 vtop 试图保持\baselineskip
与前一个框的参考点(即第一行的基线)的间距。由于无法实现这一点,TeX 放弃了基线间距,而只是插入\lineskip
粘连。
您可以在开始和结束时使用支撑,并抑制行间粘连,这样只要没有异常大的文本,间距就会保留
\tracingonline1
\tracingoutput1
\showboxdepth=4
\parindent=0pt
\newdimen\linewidth
\linewidth=4in
\newdimen\colsep
\colsep=1em
\newdimen\colwidth
\colwidth=0.5\linewidth
\advance\colwidth by -1\colsep
\def\twocols#1#2{%
\hbox to \linewidth{%
\vtop{\hsize=\colwidth
\hangindent=1em \hangafter=1 \strut#1\nobreak\strut\par}\hfill
\vtop{\hsize=\colwidth
\hangindent=1em \hangafter=1 \strut#2\nobreak\strut\par}\hss
}\par
}
\twocols
{This is a very long line that will run over}
{What is wrong with the spacing?}
\nointerlineskip
\twocols
{What is wrong with the spacing?}
{This is a very long line that will run over}
\bye
答案2
您可以继承最后一行的深度\vtop
:
\parindent=0pt
\newdimen\linewidth
\linewidth=4in
\newdimen\colsep
\colsep=1em
\newdimen\colwidth
\colwidth=0.5\linewidth
\advance\colwidth by -1\colsep
\def\twocols#1#2{%
\par
\setbox0=\vtop{\hsize=\colwidth
\hangindent=1em \hangafter=1 #1\par
\xdef\tpdA{\the\prevdepth}
}%
\setbox2=\vtop{\hsize=\colwidth
\hangindent=1em \hangafter=1 #2\par
\xdef\tpdB{\the\prevdepth}
}%
\edef\tpd{\ifdim\dp0>\dp2 \tpdA \else \tpdB\fi}%
\hbox to \linewidth{\box0 \hfill \box2}
\prevdepth=\tpd
}
\twocols
{This is a very long line that will run over over over over over over over}
{What is wrong with the spacing?}
\twocols
{What is wrong with the spacing?}
{This is a very long line that will run over}
\bye
答案3
更新处理了跳行问题。请勿在页面底部附近使用此方法。
\parindent=0pt
\newdimen\linewidth
\linewidth=4in
\newdimen\colsep
\colsep=1em
\newdimen\colwidth
\colwidth=0.5\linewidth
\advance\colwidth by -1\colsep
\def\twocols#1#2{%
\par
\hbox to\linewidth
{%
\vtop{\hsize=\colwidth
\hangindent=1em \hangafter=1 #1\par\indent}\hfill
\vtop{\hsize=\colwidth
\hangindent=1em \hangafter=1 #2\par\indent}%
}\kern-\baselineskip\hrule height0pt
\indent\par
}
\lineskip\maxdimen
\twocols
{This is a very long line that will run over over over over over over over ppppp}
{Nothing wrong with
the spacing !}
\twocols
{Nothing \smash{\vrule height \baselineskip depth 0pt width 1pt} wrong with
the spacing! YYYYYY ppppppp}
{This is a very long line that will run over}
AAAAAA\smash{\vrule height \baselineskip depth 0pt width 1pt}
\showboxbreadth \maxdimen \showboxdepth \maxdimen
\tracingoutput1
\bye
这是第三种方法。既不使用\prevdepth
(\strut
后者即使在后面跟着其他东西,也会强制使用\twocols
)。
\parindent=0pt
\newdimen\linewidth
\linewidth=4in
\newdimen\colsep
\colsep=1em
\newdimen\colwidth
\colwidth=0.5\linewidth
\advance\colwidth by -1\colsep
\def\twocols#1#2{%
\par
\hbox to\linewidth
{%
\vtop{\hsize=\colwidth
\hangindent=1em \hangafter=1 #1\par\indent}\hfill
\vtop{\hsize=\colwidth
\hangindent=1em \hangafter=1 #2\par\indent}%
}\par\kern-\baselineskip\indent\par
}
\twocols
{This is a very long line that will run over over over over over over jjjjj over}
{What is wrong with the spacing?}
\twocols
{What is wrong with the spacing?}
{This is a very long line that will run over}
\bye
答案4
那么,为什么不只是如下这样呢?
\parindent=0pt
\newdimen\linewidth
\linewidth=4in
\newdimen\colsep
\colsep=1em
\newdimen\colwidth
\colwidth=0.5\linewidth
\advance\colwidth by -\colsep
\def\singlebox#1{%
\vtop{%
\hsize=\colwidth
\hangindent=1em \hangafter=1
\leavevmode #1\par
\kern -\prevdepth
}%
}
\def\twocols#1#2{%
\par
\hbox to\linewidth
{%
\singlebox{#1}\hfill\singlebox{#2}%
}%
\prevdepth = 0pt
}
\twocols
{This is a very long line that will run over over over over over over jjjjj over}
{What is wrong with the spacing?}
\twocols
{What is wrong with the spacing?}
{This is a very long line that will run over}
More text.
% {\tracingall\showlists}
\bye
很明显,由于它“消除”了构造中底线的深度\twocols
,因此当文本包含不寻常的下降线时,此解决方案并不适用(egreg 立刻注意到了这一点)。此答案只是为了简化 jfbu 的想法。
一个可能的改进是:
\parindent=0pt
\newdimen\linewidth
\linewidth=4in
\newdimen\colsep
\colsep=1em
\newdimen\colwidth
\colwidth=0.5\linewidth
\advance\colwidth by -\colsep
\def\singlebox#1{%
\vtop{%
\hsize=\colwidth
\hangindent=1em \hangafter=1
\leavevmode #1\par
\kern -%
\ifdim\prevdepth<\maxdepth
\prevdepth
\else
\maxdepth
\fi
}%
}
\def\twocols#1#2{%
\par
\hbox to\linewidth
{%
\singlebox{#1}\hfill\singlebox{#2}%
}%
\prevdepth = 0pt
}
\twocols
{This is a very long line that will run over over over over over over jjjjj over}
{What is wrong with the spacing?}
\twocols
{What is wrong with the spacing?}
{This is a very long line that will run over}
More text.
\twocols
{This is a very long line that will run over over over over over over jjjjj
over $\Bigg|$}
{What is wrong with the spacing?}
\twocols
{What is wrong with the spacing?}
{This is a very long line that will run over}
Still more text.
% {\tracingall\showlists}
\bye
修改后的代码产生的输出是
请注意做页面底部也有效。此外,由于 OP 没有在构造\parskip
上方插入粘连\twocols
,我也没有;如果需要,可以在 的定义中的命令\vskip\parskip
之前添加显式。\hbox
\twocols