你可以定义一个近似 dash 命令,
\ExplSyntaxOn
\NewDocumentCommand \approxhdashrule { O{0pt} m m m }
{
\hbox_to_wd:nn {#2}
{
\int_set:Nn \l_tmpa_int
{
2 * \int_div_round:nn { \int_value:w \tex_dimexpr:D #2 }
{ 2 * \int_value:w \tex_dimexpr:D #4 } + 1
}
\dim_set:Nn \l_tmpa_dim { \dim_eval:n {#2} / \l_tmpa_int }
\hdashrule [#1] {#2} {#3} { \l_tmpa_dim }
\hbox_overlap_left:n { \rule [#1] { \l_tmpa_dim } {#3} }
}
}
\ExplSyntaxOff
在尾部附加了一个 \rule
。不过只能使用单个长度,不能使用不等长的(比如 1mm 2mm 1mm
)。
由于在盒子中,自带了一个组,所以无需显式使用 \begingroup ... \endgroup
。
\documentclass{article}
\usepackage{dashrule}
\setlength{\parindent}{0mm}
\begin{document}
\rule[0mm]{\linewidth}{1mm}
\hdashrule[0.5ex]{\linewidth}{0.5pt}{5mm}%
\hdashrule[0.5ex]{\linewidth}{0.5pt}{3mm}%
\hdashrule[0.5ex]{\linewidth}{0.5pt}{2mm}%
\hdashrule[0.5ex]{\linewidth}{0.5pt}{1mm}%
approximate:
\ExplSyntaxOn
\NewDocumentCommand \approxhdashrule { O{0pt} m m m }
{
\hbox_to_wd:nn {#2}
{
\int_set:Nn \l_tmpa_int
{
2 * \int_div_round:nn { \int_value:w \tex_dimexpr:D #2 }
{ 2 * \int_value:w \tex_dimexpr:D #4 } + 1
}
\dim_set:Nn \l_tmpa_dim { \dim_eval:n {#2} / \l_tmpa_int }
\hdashrule [#1] {#2} {#3} { \l_tmpa_dim }
\hbox_overlap_left:n { \rule [#1] { \l_tmpa_dim } {#3} }
}
}
\ExplSyntaxOff
\rule[0mm]{\linewidth}{1mm}
\approxhdashrule[0.5ex]{\linewidth}{0.5pt}{5mm}%
\approxhdashrule[0.5ex]{\linewidth}{0.5pt}{3mm}%
\approxhdashrule[0.5ex]{\linewidth}{0.5pt}{2mm}%
\approxhdashrule[0.5ex]{\linewidth}{0.5pt}{1mm}%
\end{document}
问 关于dashrule宏包画虚线的一个问题