TransWikia.com

Trim cdashline from arydshln package

TeX - LaTeX Asked on May 12, 2021

Is there a way to apply left or right trimming to the cdashline from the arydshln package, similar to cmidrule(lr)?

enter image description here

MWE:

documentclass{article}
usepackage{booktabs}
usepackage{arydshln}
    setlengthdashlinedash{0.5pt}
    setlengthdashlinegap{1.5pt}
    newcommand{cdotline}[1]{noalign{vskipabovetopsep}cdashline{#1}noalign{vskipbelowrulesep}}

begin{document}

begin{table}
    begin{tabular}{@{}rrr@{}}
        cdotline{2-3}
        Test & Test & Test 
        cmidrule(l){2-3}
    end{tabular}
end{table}

end{document}

2 Answers

Here is a command cdashedline which inserts trimed dashed lines. The syntax is the syntax of cline. It should be compatible with longtable.

I have not done the tuning for a behaviour exactly similar to booktabs and arydshln but it's easy to do if wanted.

documentclass{article}
usepackage{array}
usepackage{xparse}
usepackage{longtable}

ExplSyntaxOn
NewExpandableDocumentCommand { cdashedline } { }
  { 
    noalign { skip_vertical:n { 3 mm } }
    __johan_cline_i:nn 1 
  }
cs_set:Npn __johan_cline_i:nn #1 #2 { __johan_cline_i:w #1-#2 q_stop }
cs_set:Npn __johan_cline_i:w #1-#2-#3 q_stop
  {
    int_compare:nNnT { #1 } < { #2 }
      { multispan { int_eval:n { #2 - #1 } } & }
    multispan { int_eval:n { #3 - #2 + 1 } }
      { 
        skip_horizontal:N tabcolsep
        xleaders 
        hbox 
          {  
            vrule height 0.4pt depth 0pt width 2pt 
            kern 1pt 
          } 
        hfill 
        vrule height 0.4pt depth 0pt width 2pt 
        skip_horizontal:N tabcolsep
      }
    peek_meaning_remove_ignore_spaces:NTF cdashedline
      { & exp_args:Ne __johan_cline_i:nn { int_eval:n { #3 + 1 } } }
      { 
        everycr { } cr 
        noalign { skip_vertical:n { 3 mm } }
      }
  }
ExplSyntaxOff


begin{document}
begin{longtable}{cccc}
text & text & other text & more text 
text & text & other text & more text 
text & text & other text & more text 
cdashedline{2-3} cdashedline{4-4} 
text & text & other text & more text 
text & text & other text & more text 
end{longtable}
end{document}

Output of the above code

Correct answer by F. Pantigny on May 12, 2021

In {NiceTabular} of nicematrix (≥ 4.0 of 2020-05-08), you can draw with Tikz whatever rule you want using the PGF/Tikz nodes created by nicematrix under the tabular.

documentclass{article}
usepackage{booktabs}
usepackage{nicematrix}
usepackage{tikz}

begin{document}

begin{NiceTabular}{rrr}
Test & Test & Test 
Test & Test & Test 
cmidrule(l){2-3}
CodeAfter
tikz [dotted , shorten < = cmidrulekern]
  draw [shorten < = cmidrulekern] (2-|2) -- (2-|4) ;
end{NiceTabular}

end{document}

Output of the above code

Answered by F. Pantigny on May 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP