I have the following piece of code from this answer for generating a dashed table rule:
\documentclass{article}
\usepackage{booktabs}
\usepackage{arydshln}
\begin{document}
\makeatletter
\def\adl@drawiv#1#2#3{%
\hskip.5\tabcolsep
\xleaders#3{#2.5\@tempdimb #1{1}#2.5\@tempdimb}%
#2\z@ plus1fil minus1fil\relax
\hskip.5\tabcolsep}
\newcommand{\cdashrule}[2][]{%
\noalign{\vskip\aboverulesep
\global\let\@dashdrawstore\adl@draw
\global\let\adl@draw\adl@drawiv}
\cdashline{#2}
\noalign{\global\let\adl@draw\@dashdrawstore
\vskip\belowrulesep}}
\makeatother
\begin{table}
\begin{tabular}{lll}
A & B & C \\
\cdashrule{1-2}
D & E & F
\end{tabular}
\end{table}
\end{document}
I'd like to adapt \cdashrule
to take an optional argument (empty by default) that it passes to \cdashline
so that I can also control the formatting of the dashed line (line/gap width). However, even just defining an optional argument (and not using it anywhere) already causes the above example to throw errors:
\newcommand{\cdashrule}[2][]{%
\noalign{\vskip\aboverulesep
\global\let\@dashdrawstore\adl@draw
\global\let\adl@draw\adl@drawiv}
\cdashline{#2}
\noalign{\global\let\adl@draw\@dashdrawstore
\vskip\belowrulesep}}
I've also set up an Overleaf project that demonstrates this issue. How do I properly define the \cdashrule
command so that it passes any optional formatting argumenets to the underlying \cdashline
command?
\cdashline
original syntax is for optional argument after mandatory one, it would probably be better to do the same here.