-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incompatibility with colortbl
package breaks table-number-alignment
of siunitx columns
#512
Comments
It seems it's caused by the special alignment code in Following example is an attempt to cancel that special treatment for \documentclass{article}
\usepackage{colortbl}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\ExplSyntaxOn
\makeatletter
\cs_undefine:N \__tblr_siunitx_process:Nn
\cs_new_protected:Npn \__tblr_siunitx_process:Nn #1 #2
{
\__tblr_siunitx_restore_align: % <<< added
\tl_if_head_is_group:nTF {#2}
{ #2 }
{
\group_begin:
\tl_set:Nx \l_tmpa_tl
{
\__tblr_data_item:neen { cell }
{ \int_use:N \c@rownum } { \int_use:N \c@colnum } { si }
}
\exp_args:NV \sisetup \l_tmpa_tl
#1 {#2}
\group_end:
}
}
\hook_gput_code:nnn {begindocument} {tabularray}
{
\@ifpackageloaded { colortbl }
{
% quite fragile
% see https://github.com/josephwright/siunitx/blob/2bf3bd790e58894d8de2cafcc1f8f0da9eb2af19/siunitx-table.dtx#L673-L688
\cs_new_protected:Npn \__tblr_siunitx_restore_align:
{ \cs_set_eq:NN \__siunitx_table_align_auxi:nn \__siunitx_table_align_auxii:nn }
}
{
\cs_new_eq:NN \__tblr_siunitx_restore_align: \prg_do_nothing:
}
}
\makeatother
\ExplSyntaxOff
\begin{document}
\parindent=-\parindent
tabular, \verb|S[...]| \\
\begin{tabular}{
|S[table-alignment-mode=format,table-number-alignment=right]
|S[table-alignment-mode=format,table-number-alignment=center]
|S[table-alignment-mode=format,table-number-alignment=right]
|
}
{Some values} & {Some values} & {Some values} \\
1.1 & 2.2 & 3.3 \\
11.1 & 22.2 & 33.3
\end{tabular}
tblr \verb|S[...]|, \verb|halign=c| applied \\
\begin{tblr}{
|S[table-alignment-mode=format,table-number-alignment=right]
|S[table-alignment-mode=format,table-number-alignment=center]
|S[table-alignment-mode=format,table-number-alignment=left]
|
}
{{{Some values}}} & {{{Some values}}} & {{{Some values}}} \\
1.1 & 2.2 & 3.3 \\
11.1 & 22.2 & 33.3
\end{tblr}
tblr, \verb|X[<halign>, si={...}]| \\
\begin{tblr}{
|X[r,si={table-alignment-mode=format,table-number-alignment=right}]
|X[c,si={table-alignment-mode=format,table-number-alignment=center}]
|X[l,si={table-alignment-mode=format,table-number-alignment=left}]
|
}
1.1 & 2.2 & 3.3 \\
11.1 & 22.2 & 33.3
\end{tblr}
tblr, \verb|X[si={...}]| \\
\begin{tblr}{
|X[si={table-alignment-mode=format,table-number-alignment=right}]
|X[si={table-alignment-mode=format,table-number-alignment=center}]
|X[si={table-alignment-mode=format,table-number-alignment=left}]
|
}
1.1 & 2.2 & 3.3 \\
11.1 & 22.2 & 33.3
\end{tblr}
\end{document} |
This needs to be fixed in |
@lvjr Is there a marker I can pick up to know we are in a |
@josephwright How about checking |
I have a fix in hand - I'll patch in the next release (probably next week). |
Would checking nesting level ( |
There's a reason I asked if I can pick up being in a |
@lvjr I can't add a test at the moment in |
@josephwright The dev version of But |
@muzimuzhi Thanks - I might have to test without deprecation checking for this case then - should be safe enough in this one case. |
But a |
@lvjr That's why I was asking about a marker - I wondered if there was flag that was on in a cell but turned off for nested tabulars - I take it 'no' |
For nested |
Ideally, \prg_new_conditional:Npnn \tblr_if_si_cell: { p, T, F, TF }
{
\bool_lazy_and:nnTF
{ \l__tblr_if_si_column_bool } % need to be set true by "si" column type
{ \tblr_if_tblr_env_p: }
{ \prg_return_true: }
{ \prg_return_false: }
}
\prg_new_conditional:Npnn \tblr_if_tblr_env: { p, T, F, TF }
{
\tl_if_exist:cT { l__tblr_default_ \@currenvir _inner_tl }
} Alternatively, |
After reading again your workaround code above, I believe this is the most reliable solution: |
MWE:
Unless you disable
\usepackage{colortbl}
, all columns will be incorrectly left-aligned. Other alignment options such asc
seem to work. Package loading order does not matter.I have not found a prior report of this issue. For practical relevance, I use a documentclass that does
\usepackage[table]{xcolor}
and this breaks my table alignment (krono/swathesis#64). A workaround is available (not loadingcolortbl
), so I'm just reporting this for others.PS: Thanks for this awesome package!
The text was updated successfully, but these errors were encountered: