带有引线的固定高度的 \vbox 没有填满整个

带有引线的固定高度的 \vbox 没有填满整个

我正在尝试一些示例。它们在文本周围制作一个框架。我知道已经有实现的命令,但我想在 LaTeX 中练习引线、规则和方框。因此下面的示例有点人为。

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}

\begin{document}
% defining new box types
\newsavebox{\textbox}
\newsavebox{\borderbox}
\sbox{\borderbox}{*}
\sbox{\textbox}{\parbox[b]{0.5\textwidth}{The origins of mathematical thought lie in the concepts of number, patterns in nature, magnitude, and form. Modern studies of animal cognition have shown that these concepts are not unique to humans. Such concepts would have been part of everyday life in hunter-gatherer societies. The idea of the "number" concept evolving gradually over time is supported by the existence of languages which preserve the distinction between "one", "two", and "many", but not of numbers larger than two.}}

\section{With leaders}
% to see the sizes of \textbox
height=\the\ht\textbox,\quad depth=\the\dp\textbox

% \totalht = \ht\textbox + \dp\textbox (height + depth)
\newlength{\totalht}
\setlength{\totalht}{\ht\textbox}
\addtolength{\totalht}{\dp\textbox}

% \totalwd = \wd\textbox + 2\wd\borderbox
\newlength{\totalwd}
\setlength{\totalwd}{\wd\textbox}
\addtolength{\totalwd}{2\wd\borderbox} % one \wd for the left asterisk(*) and one for the right

% managing the placement
\vbox{%
\hbox to \totalwd{\leaders\copy\borderbox\hfil}%
\hbox{%
\vbox to \totalht{\leaders\copy\borderbox\vfil}%
\copy\textbox%
\vbox to \totalht{\leaders\copy\borderbox\vfil}}%
\hbox to \totalwd{\leaders\copy\borderbox\hfil}}

\section{With rules}
\vbox{%
\hrule%
\hbox{%
\vrule%
\copy\textbox%
\vrule}%
\hrule}
\end{document}

第二个示例运行正常。它使用规则制作了带框的文本。第一个例子有一个问题。如果编译上面的代码,可以注意到星号的垂直框有点不完整。文本的最后一行(从单词“numbers”开始)需要在左侧和右侧添加星号。如何自动制作?在我的代码中,我尝试计算文本框的总高度并使文本框\vbox具有此高度,但不知何故它们更短。此外,如果我增加\totalht,问题仍然存在...我应该在代码中更改什么?

在此处输入图片描述

答案1

您的代码中有三个问题。

首先:\leaders原始命令将其项目之间没有空格地放置,但无法精确实现给定的宽度或高度。您可以改用\xleaders\leaders然后可以精确实现给定的宽度和高度,但项目之间的空格很少(您的示例中为 *)。您不能同时要求这两个属性。

第二:\vbox带框架的 es 深度为零,它们被放置在 的基线\textbox,而不是 的底部\textbox。您必须将它们向下移动 的深度\textbox

第三:outer 里面的盒子\vbox是按照基线定位的,也就是说它们之间有垂直空间。这些空间可以通过\offinterlineskip宏删除。

修正后的代码:

\newbox\borderbox
\newbox\textbox

\setbox\borderbox=\hbox{*}
\setbox\textbox=\vbox{\hsize=.5\hsize The origins of mathematical thought lie in the concepts of number, patterns in nature, magnitude, and form. Modern studies of animal cognition have shown that these concepts are not unique to humans. Such concepts would have been part of everyday life in hunter-gatherer societies. The idea of the "number" concept evolving gradually over time is supported by the existence of languages which preserve the distinction between "one", "two", and "many", but not of numbers larger than two.}

\def\totalwd{\dimexpr\wd\textbox+2\wd\borderbox\relax}
\def\totalht{\dimexpr\ht\textbox+\dp\textbox}

\vbox{\offinterlineskip
\hbox to \totalwd{\xleaders\copy\borderbox\hfil}%
\hbox{%
\lower\dp\textbox\vbox to \totalht{\xleaders\copy\borderbox\vfil}%
\copy\textbox%
\lower\dp\textbox\vbox to \totalht{\xleaders\copy\borderbox\vfil}}%
\hbox to \totalwd{\xleaders\copy\borderbox\hfil}}

\bye

答案2

您想将文本框置于星号宽度或高度的整数倍内。

\documentclass[a4paper,12pt]{article}

% defining new box types
\newsavebox{\textbox}
\newsavebox{\borderbox}
\newlength{\textboxwd}
\newlength{\textboxht}

\sbox{\borderbox}{*}

\newcommand{\sometext}{The origins of mathematical thought lie in 
  the concepts of number, patterns in nature, magnitude, and form. 
  Modern studies of animal cognition have shown that these concepts
  are not unique to humans. Such concepts would have been part of
  everyday life in hunter-gatherer societies. The idea of the
  ``number'' concept evolving gradually over time is supported by
  the existence of languages which preserve the distinction between
  ``one'', ``two'', and ``many'', but not of numbers larger than two.}

\begin{document}

% set the box to the desired width, with the reference point at the bottom
\setbox\textbox=\vbox{\hsize=0.5\textwidth\sloppy\noindent\sometext\par\vspace{0pt}}
% round the height up to the nearest multiple of the height of \box\borderbox
\setlength{\textboxht}{\fpeval{ceil(\ht\textbox/(\ht\borderbox))}\ht\borderbox}
% round the width up to the nearest multiple of the width of \box\borderbox
\setlength{\textboxwd}{\fpeval{ceil(\wd\textbox/(\wd\borderbox))}\wd\borderbox}

% typeset
\hbox to \dimeval{\textboxwd+2\wd\borderbox}{\xleaders\copy\borderbox\hfill}
\nointerlineskip
\hbox{%
  \vbox to \textboxht{\xleaders\copy\borderbox\vfill}%
  \vbox to \textboxht{
    \vss
    \hbox to \textboxwd{\hss\copy\textbox\hss}
    \vss\vss
  }%
  \vbox to \textboxht{\xleaders\copy\borderbox\vfill}%
}
\nointerlineskip
\hbox to \dimeval{\textboxwd+2\wd\borderbox}{\xleaders\copy\borderbox\hfill}

\end{document}

在此处输入图片描述

答案3

也许是类似

在此处输入图片描述

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}

\begin{document}
% defining new box types
\newsavebox{\textbox}
\newsavebox{\borderbox}
\sbox{\borderbox}{$\ast$}
\sbox{\textbox}{\parbox[b]{0.5\textwidth}{The origins of mathematical thought lie in the concepts of number, patterns in nature, magnitude, and form. Modern studies of animal cognition have shown that these concepts are not unique to humans. Such concepts would have been part of everyday life in hunter-gatherer societies. The idea of the "number" concept evolving gradually over time is supported by the existence of languages which preserve the distinction between "one", "two", and "many", but not of numbers larger than two.}}

\section{With leaders}
% to see the sizes of \textbox
height=\the\ht\textbox,\quad depth=\the\dp\textbox

% \totalht = \ht\textbox + \dp\textbox (height + depth)
\newlength{\totalht}
\setlength{\totalht}{\ht\textbox}
\addtolength{\totalht}{\dp\textbox}


% \totalwd = \wd\textbox + 2\wd\borderbox
\newlength{\totalwd}
\setlength{\totalwd}{\wd\textbox}
\addtolength{\totalwd}{2\wd\borderbox} % one \wd for the left asterisk(*) and one for the right

% managing the placement
\vbox{%
\hbox to \totalwd{\cleaders\copy\borderbox\hfil}%
\hbox{%
\vbox to \totalht{\leaders\copy\borderbox\vfil\kern-.7\baselineskip}%
\copy\textbox%
\vbox to \totalht{\leaders\copy\borderbox\vfil\kern-.7\baselineskip}}%
\hbox to \totalwd{\cleaders\copy\borderbox\hfil}}

\section{With rules}
\vbox{%
\hrule%
\hbox{%
\vrule%
\copy\textbox%
\vrule}%
\hrule}
\end{document}

相关内容