Skip to content

Instantly share code, notes, and snippets.

@L3viathan
Created June 17, 2020 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save L3viathan/94beca55c92f0ded6bc1765082dea374 to your computer and use it in GitHub Desktop.
Save L3viathan/94beca55c92f0ded6bc1765082dea374 to your computer and use it in GitHub Desktop.
Easier \cmidrule things, thanks to https://tex.stackexchange.com/a/549873/72038
\usepackage{xparse}
\ExplSyntaxOn
\NewExpandableDocumentCommand{\cmidrulez}{m}
{
\noalign { \__leviathan_cmidrulez:n { #1 } }
\tl_use:N \g__leviathan_cmidrulez_tl
}
\tl_new:N \g__leviathan_cmidrulez_tl
\int_new:N \l__leviathan_cmidrulez_int
\cs_new_protected:Nn \__leviathan_cmidrulez:n
{
\tl_gclear:N \g__leviathan_cmidrulez_tl
\int_zero:N \l__leviathan_cmidrulez_int
\clist_map_inline:nn { #1 }
{
\str_if_eq:nnTF { ##1 } { * }
{% no rule here
\int_incr:N \l__leviathan_cmidrulez_int
}
{
\tl_gput_right:Nx \g__leviathan_cmidrulez_tl
{
\exp_not:N \cmidrule(lr)
{% start
\int_eval:n { \l__leviathan_cmidrulez_int + 1 }
-
\int_eval:n { \l__leviathan_cmidrulez_int + ##1 }
}
}
\int_add:Nn \l__leviathan_cmidrulez_int { ##1 }
}
}
}
\ExplSyntaxOff
\begin{table}[h]
\centering
\begin{tabular}{lllll}
\toprule
\multirow{2}{*}{Models} & \multicolumn{3}{c}{Metric 1} & Metric 2\\
\cmidrulez{*,3,1} \\
{} & precision & recall & F-score & R@10 \\
\midrule
model 1 & 0.67 & 0.8 & 0.729 & 0.75 \\
model 2 & 0.8 & 0.9 & 0.847 & 0.85 \\
\bottomrule
\end{tabular}
\end{table}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment