Open u-fischer opened 6 months ago
Something like this could work, but needs more testing ...
\DocumentMetadata{uncompress,testphase={phase-I,table},pdfversion=2.0}
\documentclass{article}
\usepackage{array,booktabs,longtable}
\makeatletter
\tagpdfsetup{role/new-tag=rule/Artifact}
\ExplSyntaxOn
\def\@cmidrulea{%
\multispan\@cmidla
%?????????? something needed here??
&\multispan\@cmidlb
\unskip\hskip\cmrkern@l%
{%
{\tl_set:Nn\l__tbl_rowtag_tl{rule}\exp_args:No\tbl_update_multicolumn_cell_data:n {\@cmidlb}}
\CT@arc@\leaders\hrule \@height\@thisrulewidth\hfill\kern\z@}%
\hskip\cmrkern@r\cr}%
\def\@cmidruleb{%
\multispan\@cmidlb
\unskip\hskip \cmrkern@l%
{{\tl_set:Nn\l__tbl_rowtag_tl{rule}\exp_args:No\tbl_update_multicolumn_cell_data:n {\@cmidlb}}%
\CT@arc@\leaders\hrule \@height\@thisrulewidth\hfill\kern\z@}%
\hskip\cmrkern@r\cr}%
\ExplSyntaxOff
\begin{document}
\begin{tabular}{l}
aaaa\\
\cmidrule{1-1}
bbbb
\end{tabular}
\begin{tabular}{lll}
aaaa&aaa&bbb\\
\cmidrule{1-2}
bbbb&aaa&bbb
\end{tabular}
\begin{longtable}{r}
aaaa\\
\midrule %fails
bbbb
\end{longtable}
\end{document}
The above code doesn't work: the row count gets confused as every cmidrule is effectively a row and it is then e.g. no longer possible to set rows below a cmidrule as header.
This here works better and makes the rules to artifacts:
\DocumentMetadata{uncompress,testphase={phase-III,table}}
\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\makeatletter
\ExplSyntaxOn
\DebugTablesOn
\def\@cmidrulea{%
\multispan\@cmidla
&\multispan\@cmidlb
\unskip\hskip\cmrkern@l%
{%
\tag_mc_begin:n{artifact}
\CT@arc@\leaders\hrule \@height\@thisrulewidth\hfill\kern\z@}%
\hskip\cmrkern@r
\tag_mc_end: \int_gdecr:N \g__tbl_row_int
\cr}%
\def\@cmidruleb{%
\multispan\@cmidlb
\unskip\hskip \cmrkern@l%
{%
\tag_mc_begin:n{artifact}
\CT@arc@\leaders\hrule \@height\@thisrulewidth\hfill\kern\z@}%
\hskip\cmrkern@r
\tag_mc_end: \int_gdecr:N \g__tbl_row_int
\cr}%
\ExplSyntaxOff
\begin{document}
\tagpdfsetup{table/header-rows=2}
\begin{tabular}{rl}
\toprule
aaa & ccc\\
\cmidrule(lr){1-1}\cmidrule(lr){2-2}
bbb\\
cccc
\end{tabular}
\begin{tabular}{r}
aaa\\
\midrule
bbb
\end{tabular}
\begin{tabular}{rl}
aaa & ccc\\
\cmidrule(lr){1-1}\cmidrule(lr){2-2}
bbb
\end{tabular}
\begin{longtable}{r}
aaaa\\
\midrule
bbbb
\end{longtable}
\ExplSyntaxOn
\begin{tabular}{r}
aaa\\
\multispan 1~\tagmcbegin{artifact}xxx\tagmcend \int_gdecr:N \g__tbl_row_int \cr %fails
bbb
\end{tabular}
\ExplSyntaxOff
\end{document}
(extracted from https://github.com/latex3/tagging-project/issues/38#issuecomment-2000322368)
In some cases booktabs inserts a
\multispan
into the table (through the commands\@cmidruleb
and\@cmidrulea
and this then errors with the tagging code. This affects both tabular and longtable (but longtable more as booktabs handles lines in longtable differently)