\label 与 gb4e 一起使用时似乎需要空格

\label 与 gb4e 一起使用时似乎需要空格

我尝试将示例排版gb4e在同一页上。我通过两个短代码扩展了 gb4e,这些短代码将示例包装在表格环境中。直到最近,这种方法都有效,但现在我\label在示例中遇到了问题。\label似乎占用了空间。

带有标签的话,会有一个额外的换行符:

在此处输入图片描述

\documentclass{article}

\usepackage{gb4e}


\makeatletter
\def\eas{\ifnum\@xnumdepth=0\begin{exe}[(34)]\else\begin{xlist}[iv.]\fi\ex\begin{tabular}[t]{@{}p{.98\linewidth}@{}}}
\def\zs{\end{tabular}\ifnum\@xnumdepth=1\end{exe}\else\end{xlist}\fi}
\makeatother



\begin{document}

\eas
\label{x}%
This is a very long sentence that goes on and on and on.
This is a very long sentence that goes on and on and on.
This is a very long sentence that goes on and on and on.
\zs

\eas
This is a very long sentence that goes on and on and on.
This is a very long sentence that goes on and on and on.
This is a very long sentence that goes on and on and on.
\zs

\end{document}

答案1

你所看到的可以归结为

\parindent=0pt
(1)\vtop{\write0{x}This}

(2)\vtop{This}

输出:

在此处输入图片描述

tabular命令中的开始\eas一个\vtop(一个\vbox在顶部对齐的), 执行\label一个\write。但是,当\vtop开始时,TeX 处于垂直模式,因此\label( \write) 被添加到当前垂直列表(好像它在自己的一行上),然后当你的段落开始时,TeX 将它添加到垂直列表中的 下方\write,使其看起来像是跳过了一行。

解决方案是不要\label在垂直模式下使用:您可以将其放在文本中的其他位置,或者您可以告诉 TeX 在\vtop开始使用后立即明确退出垂直模式\leavevmode:此时您可能不需要在垂直模式下使用它。因此,\leavevmode在定义的末尾添加可以\eas解决问题:

在此处输入图片描述

\documentclass{article}
\usepackage{gb4e}

\makeatletter
\def\eas{\ifnum\@xnumdepth=0\begin{exe}[(34)]\else\begin{xlist}[iv.]\fi
  \ex\begin{tabular}[t]{@{}p{.98\linewidth}@{}}%
  \leavevmode} %<-- added
\def\zs{\end{tabular}\ifnum\@xnumdepth=1\end{exe}\else\end{xlist}\fi}
\makeatother

\begin{document}

\eas
\label{x}%
This is a very long sentence that goes on and on and on.
This is a very long sentence that goes on and on and on.
This is a very long sentence that goes on and on and on.
\zs

\eas
This is a very long sentence that goes on and on and on.
This is a very long sentence that goes on and on and on.
This is a very long sentence that goes on and on and on.
\zs

\end{document}

相关内容