我想要一个像\midrule
booktabs 包中的一样的虚线规则。
我从 booktabs.sty 中获取了代码,对其进行了简化,并得到:
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\makeatletter{}
\def\dotrule{\noalign{\ifnum0=`}\fi
\@aboverulesep=\aboverulesep
\global\@belowrulesep=\belowrulesep
\global\@thisruleclass=\@ne
\@BTdotted}
\def\@BTdotted{%
{\CT@arc@\hrule\@height\@thisrulewidth}%
\futurenonspacelet\@tempa\@BTendrule}
\makeatother{}
\begin{document}
Text
\begin{tabular}{lr}\toprule
Huu& Haa \\\dotrule
\end{tabular}
\end{document}
\hrule\@height\@thisrulewidth
现在我只能用一些不是线而是点的东西来代替中心。我一直在努力\leaders
,但没有得到答案。也许有人有主意。
当然,我发现了很多类似的问题。但诀窍是使用 booktabs 包的参数命令!
答案1
这是一个遵循(、和)\dotrule
语法和参数的命令,但仅在环境中可用。虚线由 Tikz 绘制(可以使用 Tikz 的工具更改该虚线的特性)。booktabs
aboverulesep
belowrulesep
lightrulewidth
{NiceTabular}
nicematrix
\documentclass{article}
\usepackage{nicematrix}
\usepackage{booktabs}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{xcolor}
\ExplSyntaxOn
\makeatletter
\cs_set:Npn \dotrule
{
\noalign \bgroup
\peek_meaning:NTF [
{ \__dose_dotrule: }
{ \__dose_dotrule: [ \lightrulewidth ] }
}
\cs_set:Npn \__dose_dotrule: [ #1 ]
{
\skip_vertical:n { \aboverulesep + \belowrulesep + #1 }
\egroup
\tl_gput_right:Nx \g_nicematrix_code_after_tl
{ \__dose_dotrule:nn { \int_use:N \c@iRow } { #1 } }
}
\cs_new_protected:Nn \__dose_dotrule:nn
{
{
\dim_set:Nn \l_tmpa_dim { \aboverulesep + ( #2 ) / 2 }
\CT@arc@
\tikz \draw [ dotted , line~width = #2 ]
([yshift=-\l_tmpa_dim]#1-|1)
--
([yshift=-\l_tmpa_dim]#1-| \int_eval:n { \c@jCol + 1 }) ;
}
}
\makeatother
\ExplSyntaxOff
\begin{document}
\begin{NiceTabular}{cc}
\toprule
Header 1 & Header 2 \\
\dotrule
text & text \\
some text & other text \\
\bottomrule
\end{NiceTabular}
%
\hspace{2cm}
%
\begin{NiceTabular}{cc}
\toprule
Header 1 & Header 2 \\
\midrule
text & text \\
some text & other text \\
\bottomrule
\end{NiceTabular}
\vspace{1cm}
\arrayrulecolor{blue}
\begin{NiceTabular}{cc}
\toprule
Header 1 & Header 2 \\
\dotrule[3pt]% <-- mandatory
text & text \\
some text & other text \\
\bottomrule
\end{NiceTabular}
%
\hspace{2cm}
%
\begin{NiceTabular}{cc}
\toprule
Header 1 & Header 2 \\
\midrule[3pt]
text & text \\
some text & other text \\
\bottomrule
\end{NiceTabular}
\end{document}
答案2
一个简单的解决方案与booktabs
环境tabularray
包裹:
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\begin{booktabs}{lll}
\toprule
Alpha & Beta & Gamma \\
\midrule[dashed]
Epsilon & Zeta & Eta \\
\midrule[dotted]
Iota & Kappa & Lambda \\
\bottomrule
\end{booktabs}
\end{document}