如何正确对齐连续的\leaders?

如何正确对齐连续的\leaders?

我正在尝试构建一个带有固定填充的框的结构,\leaders后面跟着\leaders\hfill但是目前这两者之间存在一点间隙,使得图案不规则,但我希望整条线的符号等距。在下面的 MWE 中,您将看到 (输出) 行中的问题:::::和之间的间隙.....有点太大(红色箭头)。此外,和以下领导者之间的距离A因(绿色箭头)的存在而不同\hbox

\cleaders用 代替效果会更好\leaders(如下面四行所示)。

例子

\documentclass{article}

\newlength{\dotskip}
\setlength{\dotskip}{1mm}

\begin{document}

A \hbox to 20\dotskip {\leaders\hbox to \dotskip {\hss:\hss}\hfill}B

A \leaders\hbox to \dotskip {\hss:\hss}\hfill B

A \leaders\hbox to \dotskip {\hss.\hss}\hfill B

A \hbox to 5\dotskip {\leaders\hbox to \dotskip {\hss:\hss}\hfill}%
   \leaders\hbox to \dotskip {\hss.\hss}\hfill B


\bigskip
A \hbox to 20\dotskip {\cleaders\hbox to \dotskip {\hss:\hss}\hfill}B

A \cleaders\hbox to \dotskip {\hss:\hss}\hfill B

A \cleaders\hbox to \dotskip {\hss.\hss}\hfill B

A \hbox to 5\dotskip {\cleaders\hbox to \dotskip {\hss:\hss}\hfill}%
   \cleaders\hbox to \dotskip {\hss.\hss}\hfill B

\end{document}

重新表述问题

我如何将\leaders包含在(示例中的冒号)中的内容与位于(示例中的句点)外部的\hbox“全局”网格上的内容对齐。\leaders\hbox

\documentclass[a5paper]{scrbook}

\usepackage[right=50mm,marginparsep=5mm,marginparwidth=40mm,left=10mm]{geometry}
\usepackage{xcolor}
\setlength{\parindent}{0pt}
\newcommand{\margbox}[1]{%
   \unskip\marginpar{%
      \itshape
      \tiny
      #1\par
   }\ignorespaces
}

\newlength{\dotskip}
\setlength{\dotskip}{3mm}

\begin{document}

{\tiny\itshape
\textcolor{green}{left edge of leader hbox grid box}\qquad
\textcolor{red}{middle of box}\qquad
\textcolor{blue}{right edge of box}
\par}

\kern0pt
\strut\leaders\hbox to \dotskip {%
   \smash{\color{green}\vrule height 1ex depth 100mm width 0.15pt}%
   \hss
   \smash{\color{red}\vrule height 1ex depth 100mm width 0.3pt}%
   \hss
   \smash{\color{blue}\vrule height 1ex depth 100mm width 0.15pt}%
}\hfill\strut
\normalcolor

\minisec{\texttt{\string\leaders}}
A \hbox to 10\dotskip {\leaders\hbox to \dotskip {\hss:\hss}\hfill}B
   \margbox{fixed width hbox}

A \leaders\hbox to \dotskip {\hss.\hss}\hfill B
   \margbox{hfill}

A \hbox to 5\dotskip {\leaders\hbox to \dotskip {\hss:\hss}\hfill}%
   \leaders\hbox to \dotskip {\hss.\hss}\hfill B
   \margbox{fixed width hbox + hfill}

AAAA \hbox to 5\dotskip {\leaders\hbox to \dotskip {\hss:\hss}\hfill}%
   \leaders\hbox to \dotskip {\hss.\hss}\hfill B
   \margbox{fixed width hbox + hfill}


\minisec{\texttt{\string\cleaders}}
A \hbox to 10\dotskip {\cleaders\hbox to \dotskip {\hss:\hss}\hfill}B
   \margbox{fixed width hbox}

A \cleaders\hbox to \dotskip {\hss.\hss}\hfill B
   \margbox{hfill}

A \hbox to 5\dotskip {\cleaders\hbox to \dotskip {\hss:\hss}\hfill}%
   \cleaders\hbox to \dotskip {\hss.\hss}\hfill B
   \margbox{fixed width hbox + hfill}

AAAA \hbox to 5\dotskip {\cleaders\hbox to \dotskip {\hss:\hss}\hfill}%
   \cleaders\hbox to \dotskip {\hss.\hss}\hfill B
   \margbox{fixed width hbox + hfill}


\minisec{\texttt{\string\leaders}}
A \hbox to 10\dotskip {\xleaders\hbox to \dotskip {\hss:\hss}\hfill}B
   \margbox{fixed width hbox}

A \xleaders\hbox to \dotskip {\hss.\hss}\hfill B
   \margbox{hfill}

A \hbox to 5\dotskip {\xleaders\hbox to \dotskip {\hss:\hss}\hfill}%
   \xleaders\hbox to \dotskip {\hss.\hss}\hfill B
   \margbox{fixed width hbox + hfill}

AAAA \hbox to 5\dotskip {\xleaders\hbox to \dotskip {\hss:\hss}\hfill}%
   \xleaders\hbox to \dotskip {\hss.\hss}\hfill B
   \margbox{fixed width hbox + hfill}

\end{document}

该示例以一些显示“全局”网格的彩色线条开始(红线 = 网格上方框的中间)。然后是和的不同结果\leaders。实际上,我想要 的行为,即坚持使用网格,但似乎获得了自己的网格,而不是坚持使用全局网格。\cleaders\xleaders\leaders\hbox

答案1

首先,仅\leaders保证不同线路之间的对齐。

然而,\leaders当它们共享封闭框级别时,可以保证对齐。

考虑以下普通的 TeX 示例:

\parindent=0pt

\def\lb{\hbox{\kern1mm\hss.\hss\kern1mm}}

\hbox to 4cm{\leaders\lb\hfil}

\hbox{\kern3.7mm\hbox to 3.63cm{\leaders\lb\hfil}}

\vtop{
  \leavevmode\leaders\lb\hskip4cm\kern0pt\par
  \leavevmode\kern3.7mm\leaders\lb\hskip3.63cm\kern0pt\par
  \leavevmode\hbox to 4cm{\leaders\lb\hskip4cm}\par
  \leavevmode\hbox to 4cm{\kern3.7mm\leaders\lb\hskip3.63cm}\par
}

\bye

如您所见,前两行句点没有对齐,而后四行对齐了。

在此处输入图片描述

答案2

参考:Heiko 的精彩描述 https://tex.stackexchange.com/a/253303/25858

  • \leaders将框设置为固定网格位置。例如,它适用于目录中的点。这样,无论点从哪里开始,它们始终垂直对齐。

  • \xleaders计算需要多少个框才能填满空间而不会过满。然后将空间分成大小相等的部分,并将框水平居中。下面的示例用宽度为 7 pt 的框填充 20 pt 的空间。因此,两个框适合空间,结果是一条“虚线”。

  • \cleaders由于以前版本的“破折号”效果有时不太理想,因此\cleaders将框移到中间,并将剩余未填充的空间放在要填充的空间的两侧。

当要填充的空间不是前导周期的精确倍数时,就会出现问题。该怎么办?网格对齐 ( \leaders),居中并将多余的空间放在外面 ( \cleaders),或在周期之间分配多余的空间 ( \xleaders)。

因此,我将所有\leaders和更改\cleaders\xleaders

\documentclass{article}

\newlength{\dotskip}
\setlength{\dotskip}{1mm}

\begin{document}

A \hbox to 20\dotskip {\xleaders\hbox to \dotskip {\hss:\hss}\hfill}B

A \xleaders\hbox to \dotskip {\hss:\hss}\hfill B

A \xleaders\hbox to \dotskip {\hss.\hss}\hfill B

A \hbox to 5\dotskip {\xleaders\hbox to \dotskip {\hss:\hss}\hfill}%
   \xleaders\hbox to \dotskip {\hss.\hss}\hfill B


\bigskip
A \hbox to 20\dotskip {\xleaders\hbox to \dotskip {\hss:\hss}\hfill}B

A \xleaders\hbox to \dotskip {\hss:\hss}\hfill B

A \xleaders\hbox to \dotskip {\hss.\hss}\hfill B

A \hbox to 5\dotskip {\xleaders\hbox to \dotskip {\hss:\hss}\hfill}%
   \xleaders\hbox to \dotskip {\hss.\hss}\hfill B

\end{document}

在此处输入图片描述

相关内容