tabularray – Setting Column Width for Q-Column in Tabularray

column widthtabularray

I have some Q-column but using a \TblrNote seems to break the auto-width of those columns…
How can I re-adjust the width so columns 3-8 are of equal width?

\documentclass{scrartcl}
\usepackage{tabularray,xcolor,hyperref}
\UseTblrLibrary{siunitx}

\NewTblrTheme{mytheme}{
  \DefTblrTemplate{contfoot-text}{default}{Continued on next page ...}
  \DefTblrTemplate{conthead-text}{default}{(Continued)}
  \SetTblrStyle{head}{%
    fg=black}
  \SetTblrInner{%
    row{odd} = {bg=rwthBlueLight},
    row{1}={bg=blue,fg=white,font=\bfseries},
    width = \linewidth,
    hline{1,Z} = {2pt,fg=blue}, % toprule and bottomrule
    hline{2} = {1pt,fg=blue}, % midrule
    }
  }


  \hypersetup{%
    colorlinks = true,
    linkcolor = blue
  }

\begin{document}

\begin{tblr}[%
  theme=mytheme,
  long,
  note{a}={Figures in EUR},
  note{b}={Not all figures in EUR},
  ]{%
    colspec = {X[2,m]X[6,m]*{2}{Q[c]}Q[c]*{3}{Q[c]}},
    cell{1}{1-8} = {cmd={\hypersetup{linkcolor=white}}},
    rowhead = 1
  }
  {Project} %
  & Species %
  & {{{Quantity}}}
  & {{{Average\\ number of\\ weeks kept}}}
  & {{{Housing costs\\ per animal\\ per week}}}\TblrNote{a}
  & {{{Purchasing\\ costs \\per animal}}}\TblrNote{a}
  & {{{Requested\\funds}}}\TblrNote{a}
  & {{{Existing\\funds}}}\TblrNote{a}\\
  Hello & World & 123 & 45.6 & 789 & 10992.0 & 11223.5 & 32012.2\\
  \end{tblr}

\end{document}

enter image description here

Best Answer

  • Your MWE contain errors (color names).
  • Added is use of siunitx columns.
  • Interchanged are Q and X columns ...
  • for column headers I would use \small\bfseries font size

Edit:

  • We should be aware, that tags in TblrNote are in case of use hyperref package are defined by it. That tags in TblrNote will be visible, it is need to locally changed hyperref setup so, that color of tags will be the same as color of text in rows.
  • Since in table is used siunitx packages, the column headers should be in parenthesis. That hyper links will work \TblrNote had to be outside of them:
\documentclass{scrartcl}
\usepackage[svgnames]{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\sisetup{group-minimum-digits=4}
\usepackage{hyperref}
  \hypersetup{%
    colorlinks = true,
    linkcolor = blue % color is the same as the first row color!
  }

\begin{document}

\begin{longtblr}[%
  note{a}={Figures in EUR},
  note{b}={Not all figures in EUR},
                ]{%
    colsep  = 2pt,
    colspec = {*{2}{Q[l]} 
               *{3}{X[c, si={table-format=3.1}]}
               *{2}{X[1.1, c, si={table-format=5.1}]}
                    X[0.8, c, si={table-format=5.1}]
               },
    row{odd} = {bg=LightBlue},
    row{1}   = {bg=blue, fg=white, font=\small\bfseries,
                cmd={\hypersetup{linkcolor=white}} % needed that `TblrNote` tag  become visible
                },
    rowhead  = 1
                }
    \toprule[blue]
Project 
    & Species 
        & {{{Quantity}}}
            & {{{Average number of weeks kept}}}
                & {{{Housing costs per animal per week}}}\TblrNote{a}
                    & {{{Purchasing costs per animal}}}\TblrNote{a}
                        & {{{Requested funds}}}\TblrNote{a}
                            & {{{Existing funds\TblrNote{a}}}} \\
    \midrule[blue]
Hello & World & 123 & 45.6 & 789 & 10992.0 & 11223.5 & 32012.2  \\
Hello & World & 456 & 78.9 & 123 & 10992.0 &  6789.0 &  1234.5  \\
Hello & World & 123 & 45.6 & 789 & 10992.0 & 11223.5 & 32012.2  \\
Hello & World & 456 & 78.9 & 123 & 10992.0 &  6789.0 &  1234.5  \\
    \bottomrule[blue]
  \end{longtblr}
\end{document}

enter image description here

Addendum: With tabularray package version newer than 2022A the table code can be a bit simpler:

\documentclass{scrartcl}
\usepackage[svgnames]{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\sisetup{group-minimum-digits=4}
\usepackage{hyperref}
  \hypersetup{%
    colorlinks = true,
    linkcolor = blue % color is the same as the first row color!
  }

\begin{document}

\begin{longtblr}[%
  note{a}={Figures in EUR},
  note{b}={Not all figures in EUR},
                ]{%
    colsep  = 2pt,
    colspec = {*{2}{Q[l]}
               *{3}{X[c, si={table-format=3.1}]}
               *{2}{X[1.1, c, si={table-format=5.1}]}
                    X[0.8, c, si={table-format=5.1}]
               },
    row{odd} = {bg=LightBlue},
    row{1}   = {guard,    % <---
                font=\small\bfseries,
                fg=white, bg=blue,
                cmd={\hypersetup{linkcolor = white}}, % needed that `TblrNote` tag  be visible
                },
    rowhead  = 1
                }
    \toprule[blue]
Project
    & Species  % <---
        &   Qnty  % <--- 
            &   Average number of weeks kept  % <--- 
                &   Housing costs per animal per week\TblrNote{a}  % <---
                    &   Purchasing costs per animal\TblrNote{a}  % <---
                        &   Requested funds\TblrNote{a}  % <---
                            &   Existing funds\TblrNote{a}  % <---  \\
    \midrule[blue]
Hello & World & 123 & 45.6 & 789 & 10992.0 & 11223.5 & 32012.2  \\
Hello & World & 456 & 78.9 & 123 & 10992.0 &  6789.0 &  1234.5  \\
Hello & World & 123 & 45.6 & 789 & 10992.0 & 11223.5 & 32012.2  \\
Hello & World & 456 & 78.9 & 123 & 10992.0 &  6789.0 &  1234.5  \\
    \bottomrule[blue]
  \end{longtblr}
\end{document}

Compilation result is the same as before.