如何在表格的两列之间使用 \dotfill?

如何在表格的两列之间使用 \dotfill?

我想\dotfill在某个环境中使用虚线(通过命令或等效命令)tabular*,以便在两列之间的空间中也有点(如下图中的红点),但我无法管理它。

在此处输入图片描述

以下是 MWE(有一些不成功的尝试):

\documentclass{article}
\usepackage{array, booktabs}

\makeatletter
\newcommand\pfill{\leavevmode\leaders\hb@[email protected]{\hss.\hss}\hfill\kern\z@}
\makeatother

\begin{document}
\begin{tabular*}{0.6\textwidth}{@{\hspace{\tabcolsep}\extracolsep{\fill}} l<{\pfill} c}\toprule
    Blah blah blah & 123 \\
    Blah blah blah blah blah & 123456\\
    Blah blah & 123456789\\\bottomrule
\end{tabular*}

%\begin{tabular*}{0.6\textwidth}{@{\hspace{\tabcolsep}\extracolsep{\fill}} l<{\pfill} @{\pfill} c}\toprule% Does not work
%    Blah blah blah & 123 \\
%    Blah blah blah blah blah & 123456\\
%    Blah blah & 123456789\\\bottomrule
%\end{tabular*}

%\begin{tabular*}{0.6\textwidth}{@{\hspace{\tabcolsep}\extracolsep{\pfill}} l<{\pfill} c}\toprule% Does not work
%    Blah blah blah & 123 \\
%    Blah blah blah blah blah & 123456\\
%    Blah blah & 123456789\\\bottomrule
%\end{tabular*}
\end{document}

答案1

带包装nicematrix

\documentclass{article}
\usepackage{array, booktabs}
\usepackage{nicematrix}

\makeatletter
\newcommand\pfill{\leavevmode\leaders\hb@[email protected]{\hss.\hss}\hfill\kern\z@}
\makeatletter

\begin{document}
\begin{NiceTabularX}{0.6\textwidth}{X<{\pfill}@{}c}
    \toprule
    Blah blah blah & 123 \\
    Blah blah blah blah blah & 123456 \\
    Blah blah & 123456789 \\
    \bottomrule
\end{NiceTabularX}

\bigskip

\begin{NiceTabularX}{0.6\textwidth}{X[2]<{\pfill}@{\makebox[0.6em][c]{\textcolor{red}{.}}}>{\pfill}X}
    \toprule
    Blah blah blah & 123 \\
    Blah blah blah blah blah & 123456 \\
    Blah blah & 123456789 \\
    \bottomrule
\end{NiceTabularX}
\end{document}

在此处输入图片描述

答案2

如果您接受使用tabular而不是tabular*并固定(列 1 + 点)的宽度,则以下工作有效:

\documentclass{article}
\usepackage{array, booktabs}

\begin{document}
\begin{tabular}{W{c}{5cm} <{\dotfill} @{} c}
  \toprule
    Blah blah blah & 123 \\
    Blah blah blah blah blah & 123456\\
    Blah blah & 123456789\\
  \bottomrule
\end{tabular}
\end{document}

在此处输入图片描述

相关内容