我正在写一份合同,当行结束时,以及当文本居中时,使用点来填充空白处。所以我在寻找一个居中的文本,左右两侧都有点。类似于:
\dotfill text \dotfill
。我找到了一种方法,但也许还有更有效的方法:
\begin{center}
\begin{minipage}[b]{0.37 \textwidth}
\dotfill
\end{minipage}%
\begin{minipage}[b]{0.25\textwidth}
\centering
TEXTSAMPLE
\end{minipage}
\begin{minipage}[b]{0.37\textwidth}
\dotfill
\end{minipage}
\end{center}
答案1
使用最新的 LaTeX 版本,您可以执行以下操作:
\documentclass{article}
\ExplSyntaxOn
\NewDocumentEnvironment{fillcenter}{+b}
{
\begin{center}
\seq_set_split:Nnn \l_tmpa_seq { \\ } { #1 }
\dotfill \seq_use:Nn \l_tmpa_seq { \\ \dotfill }
\end{center}
}
{}
\ExplSyntaxOff
\AddToHook{para/end}[dotfill]{\ifhmode\unskip\dotfill\fi}
\begin{document}
This is a paragraph where the final blank space is
filled with dots.
This is a paragraph where the final blank space is
filled with dots.
\begin{fillcenter}
This is a centered \\
block where the \\
filling is on \\
either side
\end{fillcenter}
And this is again filled.
\end{document}
答案2
快速实验:
\documentclass{article}
\usepackage[showframe]{geometry}
\begin{document}
\begin{center}
\dotfill TEXTSAMPLE\dotfill
\end{center}
\begin{center}
\dotfill\ TEXTSAMPLE\ \dotfill
\end{center}
\begin{center}
\begin{minipage}[b]{0.37\textwidth}
\dotfill
\end{minipage}%
\begin{minipage}[b]{0.25\textwidth}
\centering
TEXTSAMPLE
\end{minipage}%
\begin{minipage}[b]{0.37\textwidth}
\dotfill
\end{minipage}
\end{center}
\end{document}