書籤:\dotrule 為 \midrule

書籤:\dotrule 為 \midrule

我想要一個像\midrulebooktabs 套件中那樣的點線規則。

我從 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

這是一個遵循( , and )\dotrule語法和參數的命令,但僅在環境中可用。虛線是由 Tikz 繪製的(可以使用 Tikz 工具更改該虛線的特徵)。booktabsaboverulesepbelowruleseplightrulewidth{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}

在此輸入影像描述

相關內容