如何避免(xparse)环境框破坏行间距并进入前一个环境框的内部空间?

如何避免(xparse)环境框破坏行间距并进入前一个环境框的内部空间?

第一个环境最后一行的行间距被下一个环境的第一行侵犯。在这种情况下,我该如何保持正确的行间距?

\documentclass[varwidth]{standalone}
\usepackage{xparse}
\begin{document}
  \NewDocumentEnvironment{myEnv}{+b}
    { \parbox{40mm}
        { #1
        }
    } {}
  \begin{myEnv}
    This is sentence 1. This is sentence 2.
     This is sentence 3.
  \end{myEnv}\par
  % INTERLINE SPACING IS BAD HERE
  \begin{myEnv}
    This is sentence 1. This is sentence 2.
     This is sentence 3.
  \end{myEnv}
\end{document}

答案1

在此处输入图片描述

由于您使用垂直居中的 parbox,它们具有很大的高度和深度,所以 tex 无法维护它们的参考点之间的基线到基线空间,所以它垂直堆叠它们,并以\lineskip(默认为 1pt)和分隔\parskip

如果添加,\strut那么堆叠的框的基线将被分隔开,\baselineskip但是仍然有额外的基线\lineskip,如第二个示例所示。

如果您对输入有足够的控制权,并且您知道您正在设置这些框的序列,那么您可以抑制\lineskipwith(例如)nointerlineskip并且只依靠 来\strut间隔行,如最后一个例子所示。

\documentclass{article}
\showoutput
\showboxdepth=3

\begin{document}

\parbox{40mm}{This is sentence 1. This is sentence 2. This is sentence 3.}


\parbox{40mm}{This is sentence 1. This is sentence 2. This is sentence 3.}



\bigskip

\parbox{40mm}{\strut This is sentence 1. This is sentence 2. This is sentence 3.\strut }


\parbox{40mm}{\strut This is sentence 1. This is sentence 2. This is sentence 3.\strut }


\bigskip

\parbox{40mm}{\strut This is sentence 1. This is sentence 2. This is sentence 3.\strut }

\nointerlineskip
\parbox{40mm}{\strut This is sentence 1. This is sentence 2. This is sentence 3.\strut }


\end{document}

三种情况的终端输出为


...\hbox(17.97223+12.97221)x345.0, glue set 216.18898fil []
...\glue(\parskip) 0.0 plus 1.0
...\glue(\lineskip) 1.0
...\hbox(17.97223+12.97221)x345.0, glue set 216.18898fil []

...\hbox(20.5+15.5)x345.0, glue set 216.18898fil []
...\glue(\parskip) 0.0 plus 1.0
...\glue(\lineskip) 1.0
...\hbox(20.5+15.5)x345.0, glue set 216.18898fil []

...\hbox(20.5+15.5)x345.0, glue set 216.18898fil []
...\glue(\parskip) 0.0 plus 1.0
...\hbox(20.5+15.5)x345.0, glue set 216.18898fil []

相关内容