如何拉伸 vbox 来适合其父 PlainTeX?

如何拉伸 vbox 来适合其父 PlainTeX?

我正在尝试创建一个带有 1pt 宽黑色边框的白色方块。这是我目前的代码:

\def\blankbox#1{
    \hbox to #1{
        \vrule
        \vbox to #1 {
            \hrule
            \vfil
            \hrule 
        }   
        \vrule
    }   
}

答案1

保护行尾并指定宽度\hrule

\def\blankbox#1{%
    \hbox to #1{%
        \vrule\hss
        \vbox to #1 {
            \hrule width #1
            \vfil
            \hrule
        }%
        \hss\vrule
    }%
}

\blankbox{1cm}

\bye

如果要改变厚度:

\def\blankbox#1#2{%
    \hbox to #2{%
        \vrule width #1 \hss
        \vbox to #2 {
            \hrule width #2 height #1
            \vfil
            \hrule height #1
        }%
        \hss \vrule width #1
    }%
}

\noindent
\blankbox{0.4pt}{1cm}\qquad\blankbox{2pt}{1cm}

\bye

这样就形成了一个框,其中的区域由规则内部限定。更通用的方法允许对规则进行不同的放置:\iblankbox如前所述,\mblankbox对于“中间”放置,\oblankbox对于“外部”放置。

\def\gblankbox#1#2#3{%
  \dimen0=#2\relax
  \dimen2=#3\relax
  \advance\dimen2 by #1\dimen0
  \hbox to \dimen2{%
    \vrule width \dimen0\hss
    \vbox to \dimen2 {
      \hrule width \dimen2 height \dimen0
      \vfil
      \hrule height \dimen0
    }%
      \hss \vrule width \dimen0
  }%
}
\def\iblankbox{\gblankbox{0}}
\def\mblankbox{\gblankbox{1}}
\def\oblankbox{\gblankbox{2}}

\noindent
\iblankbox{0.4pt}{1cm}\qquad\iblankbox{2pt}{1cm}

\noindent
\mblankbox{0.4pt}{1cm}\qquad\mblankbox{2pt}{1cm}

\noindent
\oblankbox{0.4pt}{1cm}\qquad\oblankbox{2pt}{1cm}

\noindent
\setbox0=\hbox{\iblankbox{1pt}{10pt}}
width = \the\wd0; height = \the\ht0

\noindent
\setbox0=\hbox{\mblankbox{1pt}{10pt}}
width = \the\wd0; height = \the\ht0

\noindent
\setbox0=\hbox{\oblankbox{1pt}{10pt}}
width = \the\wd0; height = \the\ht0

\bye

在此处输入图片描述

答案2

这按预期工作:

\def\blankbox#1{% <-- important!
    \hbox{% <-- important!
        \vrule width 5pt
        \kern -5pt
        \vbox to #1 {%
            \hrule height 5pt width #1
            \vfil
            \hrule height 5pt
        }% <-- important!
        \kern -5pt
        \vrule width 5pt
    }% <-- important!
}

\noindent\blankbox{3cm}

\showboxbreadth = 100
\showboxdepth = 10
\tracingonline = 1
\showlists

\dimen0 = 3cm
\showthe\dimen0

\bye

诊断命令可帮助您验证框是否确实具有您想要的尺寸。请注意,必须“注释掉”水平模式下出现的每个“行尾”(至少)。当然,在检查框是否为正方形后,在整个代码中将其替换5pt为。1pt

相关内容