Tables – Fix Issues with Cells Alignment and Horizontal Distribution in Tabularray

horizontal alignmenttablestabularray

I have been trying to set up a table with specific vertical and horizontal distribution as well as rows and cols merge with tabularray package. Below is my MWE which emphasizes the issue I am facing within the first cell cell{1}{1} = {r=2,c=1}{c} and third row row{3}.

In the example, shown below, it is possible to notice the cell named D (cell{1}{8} = {r=2,c=1}{c}) and F (cell{1}{9} = {r=2,c=1}{c}) follows the definition for center alignment based on the same code line (cell{1}{1,8,9} = {r=2,c=1}{c}).

enter image description here

I have already tried multiple colspec with given m and c align arguments as well as hspace=even and \SetTblrInner{vspan=even, hspan=even} but none managed to make the cell{1}{1} center aligned and the cell{3}{1} even with respect to the other rows.

MWE:

\usepackage{nth}
\usepackage{booktabs}
\usepackage{tabularx,booktabs}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\UseTblrLibrary{varwidth}


\begin{document}
\begin{tblr}{
    measure=vbox,
    %rows = {valign=c},
    row{1} = {bg=white, fg=black, font=\bfseries},
    cell{1}{1,8,9} = {r=2,c=1}{c}, %Defines the cell position row 1 colunm 1,8,9 as a 2 rows and 1 colunm cell with 'c' center aligment
    cell{1}{2,5} = {r=1,c=3}{c},
    %cell{1}{5} = {r=1,c=3}{c},
    %cell{1}{8} = {r=2,c=1}{c},
    %cell{1}{9} = {r=2,c=1}{c},
    hspan=even, vspan=even,
    width=1\columnwidth,
    %colspec={X[3cm,c,m] X[c,m] X[c,m] X[c,m] X[c,m] X[c,m] X[c,m] X[3cm,c,m] X[3cm,c,m]},
    colspec={Q[c,m] Q[c,m] Q[c,m] Q[c,m] Q[c,m] Q[c,m] Q[c,m] Q[c,m] Q[c,m]},
    %colspec={Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]},
    %rowspec={Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]},
    hline{4-Y} = {1,8,9}{0.5pt, rightpos = -1, leftpos = -1},
    vline{2,5,8,9} = {1pt,solid},
    hline{1,Z} = {2pt},
    hline{3} = {1,8,9}{1.5pt, rightpos = -1, leftpos = -1},
    hline{3} = {2,3,4}{1.5pt, rightpos = -1, leftpos = -1, endpos},
    hline{3} = {5,6,7}{1.5pt, rightpos = -1, leftpos = -1, endpos},
    hline{4-Y} = {2,3,4}{0.5pt, rightpos = -1, leftpos = -1, endpos},
    hline{4-Y} = {5,6,7}{0.5pt, rightpos = -1, leftpos = -1, endpos},
    vline{3,4,6,7} = {0.5pt}   
} 



A & B &   &   & C &   &   & D & F \\

    & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ &  &  \\



            \nth{1} & 
            1 & 
            2 & 
            3 &
            4 &
            5 &
            6 & 
            7 &
            8     
            \\

            \nth{2} & 
            1 & 
            2 & 
            3 &
            4 &
            5 &
            6 & 
            7 &
            8
            \\
            

            \nth{3} & 
            1 & 
            2 & 
            3 &
            4 &
            5 &
            6 & 
            7 &
            8
            \\

            \nth{4} & 
            1 & 
            2 & 
            3 &
            4 &
            5 &
            6 & 
            7 &
            8
            \\

            \nth{5} & 
            1 & 
            2 & 
            3 &
            4 &
            5 &
            6 & 
            7 &
            8
            \\

            \nth{6} & 
            1 & 
            2 & 
            3 &
            4 &
            5 &
            6 & 
            7 &
            8
            \\

            \nth{7} & 
            1 & 
            2 & 
            3 &
            4 &
            5 &
            6 & 
            7 &
            8
            \\
           

\end{tblr}
\end{table*} %Summary of the different topological stage
\end{document}

Thanks in advance for the support!

Best Answer

I am not having this issue if I run your code (I removed redundant packages):

\documentclass{article}
\usepackage{nth}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\UseTblrLibrary{varwidth}


\begin{document}
\begin{table}[tbh]
  \begin{tblr}{
      width=1\columnwidth,
      measure=vbox,
      colspec={Q[c,m] Q[c,m] Q[c,m] Q[c,m] Q[c,m] Q[c,m] Q[c,m] Q[c,m] Q[c,m]},
      %rows = {valign=c},
      row{1} = {bg=white, fg=black, font=\bfseries},
      cell{1}{1,8,9} = {r=2,c=1}{c},
      cell{1}{2,5} = {r=1,c=3}{c},
      %cell{1}{5} = {r=1,c=3}{c},
      %cell{1}{8} = {r=2,c=1}{c},
      %cell{1}{9} = {r=2,c=1}{c},
      hspan=even, vspan=even,
      %colspec={X[3cm,c,m] X[c,m] X[c,m] X[c,m] X[c,m] X[c,m] X[c,m] X[3cm,c,m] X[3cm,c,m]},
      %colspec={Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]},
      %rowspec={Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]Q[c]},
      hline{4-Y} = {1,8,9}{0.5pt, rightpos = -1, leftpos = -1},
      vline{2,5,8,9} = {1pt,solid},
      hline{1,Z} = {2pt},
      hline{3} = {1,8,9}{1.5pt, rightpos = -1, leftpos = -1},
      hline{3} = {2,3,4}{1.5pt, rightpos = -1, leftpos = -1, endpos},
      hline{3} = {5,6,7}{1.5pt, rightpos = -1, leftpos = -1, endpos},
      hline{4-Y} = {2,3,4}{0.5pt, rightpos = -1, leftpos = -1, endpos},
      hline{4-Y} = {5,6,7}{0.5pt, rightpos = -1, leftpos = -1, endpos},
      vline{3,4,6,7} = {0.5pt}
    }
    A       & B   &     &     & C   &     &     & D & F \\
            & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ &   & \\
    \nth{1} & 1   & 2   & 3   & 4   & 5   & 6   & 7 & 8 \\
    \nth{2} & 1   & 2   & 3   & 4   & 5   & 6   & 7 & 8 \\
    \nth{3} & 1   & 2   & 3   & 4   & 5   & 6   & 7 & 8 \\
    \nth{4} & 1   & 2   & 3   & 4   & 5   & 6   & 7 & 8 \\
    \nth{5} & 1   & 2   & 3   & 4   & 5   & 6   & 7 & 8 \\
    \nth{6} & 1   & 2   & 3   & 4   & 5   & 6   & 7 & 8 \\
    \nth{7} & 1   & 2   & 3   & 4   & 5   & 6   & 7 & 8 \\
  \end{tblr}
\end{table} %Summary of the different topological stage
\end{document}

enter image description here

Also, not sure if the middle alignment is intended but in case you want headers to be in one line, here's the snippet to change

% ... valgin added
row{1} = {valign=h, bg=white, fg=black, font=\bfseries},
cell{1}{1,8,9} = {r=2,c=1}{},   % c removed
% ...

enter image description here