答案1
根据的定义\ldots
:
\documentclass{article}
%For older distributions
\usepackage{expl3}
%%%%%%%%%%%%%%%%%%%%%%%%
\ExplSyntaxOn
\cs_new_protected:Npn \sebastiano_alotofdots:n #1{
\mathinner{
\prg_replicate:nn{#1}{\ldotp}
}
}
\newcommand{\alotofdots}[1][3]{\sebastiano_alotofdots:n{#1}}
\ExplSyntaxOff
\begin{document}
$\alotofdots$
$\alotofdots[7]$
$\alotofdots[14]$
\end{document}
你可以重新定义\ldots
以便它接受可选参数,但我不推荐这样做。
编辑
感谢 Andrew 和 Phelype 的建议。使用xparse
并采纳 Andrew 提出的优雅建议,更灵活的方法可能是(颜色突出显示):
\documentclass{article}
%For older distributions
\usepackage{expl3}
%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{xparse}
\ExplSyntaxOn
%Thanks, Andrew! This looks way better than my previous example. :)
\NewDocumentCommand\alotofdots{ D(){\ldotp} O{3}}
{\mathinner{\prg_replicate:nn{#2}{#1}}}
\ExplSyntaxOff
\begin{document}
%Three dots (just the same as \ldots)
$\alotofdots$
%Number of repetitions is specified by [number]
$\alotofdots[4]$
%The dot can be changed by (another symbol)
%\cdot does not work here
$\alotofdots(\cdotp)$
%And now two arguments
$\alotofdots(\cdotp)[7]$
\end{document}
答案2
这是另一种方法,\dotfill
在长度为点数加 1 的框内使用,每次1ex
。默认情况下,由 产生三个点\ndots
,可选参数会更改此设置,以便代码
\documentclass{article}
\makeatletter
\newcommand\ndots[1][3]{%
\@tempdima=\dimexpr#1ex+1ex\relax%
\hbox to \@tempdima{\dotfill}%
}
\makeatletter%
\begin{document}
default: \ndots
1: \ndots[1]
2: \ndots[2]
3: \ndots[3]
4: \ndots[4]
5: \ndots[5]
6: \ndots[6]
7: \ndots[7]
8: \ndots[8]
9: \ndots[9]
\end{document}
生成: