1

Is it possible to set all tblr in the document to be \linewidth wide specifying the X column type by default?. This requires not mentioning the number of columns like it happens in colspec, as it varies for every tblr.

In this case, colspec could be used in certain columns where the default column type should be overriden.

For instance:

\documentclass{article}
\usepackage{tabularray}

\setlength{\parindent}{0mm}

% act here to specify a default column type

\SetTblrInner{
 width=\linewidth,
 %columns={X},
 baseline=T,
 hspan=even,
 vspan=even,
 stretch=1.3,
 row{1}={font=\bfseries},
 hline{1,Z}={0.6mm},
 hline{2}={0.3mm}
}

\begin{document}

 These tables should all have the same width without further modifications in the document body

 \begin{table}[!hb]
  \begin{tblr}{colspec={XX}}
   Head1 & Head2 \\
   Row21 & Row22 \\
   Row31 & Row32 \\
  \end{tblr}

  \begin{tblr}{}
   Head1 & Head2 \\
   Row21 & Row22Row22 \\
   Row31 & Row32 \\
  \end{tblr}

  \begin{tblr}{}
   Head1 & Head2 & Head3\\
   Row21 & Row22 & Row23 \\
   Row31 & Row32 & Row33 \\
   Row41 & Row42 & Row43 \\
  \end{tblr}

  \begin{tblr}{colspec={|l|X[r]|c|}}
   Head1 & Head2 & Head3\\
   Row21 & Row22 & Row23 \\
   Row31 & Row32 & Row33 \\
   Row41Row41 & Row42 & Row43 \\
  \end{tblr}
 \end{table}
\end{document}
3
  • If a column's default width is \linewidth, how are tables with two columns, let alone tables with three or more columns, supposed to fit on a page?
    – Mico
    Commented May 20, 2023 at 17:45
  • @Mico width in SetTblrInner is referred to the whole tblr, not to single columns
    – Polizi8
    Commented May 22, 2023 at 9:52
  • 1
    I have opened a discussion related to this question in the official Github repository of the tabularray package. Commented Jun 1, 2023 at 16:26

1 Answer 1

1

You've found the right option, columns. The last step is to feed it a column key-value list, like co=1,bg=blue!20, not an other column type like X.

By uncommenting the columns={X}, line in OP's example and replacing it with columns={co=1},, you'll get

\documentclass{article}
\usepackage{tabularray}

\setlength{\parindent}{0mm}

% act here to specify a default column type

\SetTblrInner{
 width=\linewidth,
 columns={co=1},
 baseline=T,
 hspan=even,
 vspan=even,
 stretch=1.3,
 row{1}={font=\bfseries},
 hline{1,Z}={0.6mm},
 hline{2}={0.3mm}
}

\begin{document}

 These tables should all have the same width without further modifications in the document body

 \begin{table}[!hb]
  \begin{tblr}{colspec={XX}}
   Head1 & Head2 \\
   Row21 & Row22 \\
   Row31 & Row32 \\
  \end{tblr}

  \begin{tblr}{}
   Head1 & Head2 \\
   Row21 & Row22Row22 \\
   Row31 & Row32 \\
  \end{tblr}

  \begin{tblr}{}
   Head1 & Head2 & Head3\\
   Row21 & Row22 & Row23 \\
   Row31 & Row32 & Row33 \\
   Row41 & Row42 & Row43 \\
  \end{tblr}

  \begin{tblr}{colspec={|l|X[r]|c|}}
   Head1 & Head2 & Head3\\
   Row21 & Row22 & Row23 \\
   Row31 & Row32 & Row33 \\
   Row41Row41 & Row42 & Row43 \\
  \end{tblr}
 \end{table}
\end{document}

enter image description here

Update

Unfortunately, because column types like l and c only set halign (to l and c, respectively) and don't reset co to its initial value 0 (which is altered by previous columns={co=1}), after setting columns={co=1}, a table with colspec={|l|X[r]|c|} will work like

colspec={|Q[l,co=1]|Q[r,co=1]|Q[c,co=1]|}

while what user may expect is

colspec={|Q[l,co=0]|Q[r,co=1]|Q[c,co=0]|}

One workaround is to explicitly use colspec={|Q[l,co=0]|X[r]|Q[c,co=0]|}. (Currently there's no public interface to redefine an existing row/column type and column types setting horizontal alignment like l and c don't have an optional argument.)

Reported to tabularray, see https://github.com/lvjr/tabularray/issues/411.

\documentclass{article}
\usepackage{tabularray}

\setlength{\parindent}{0mm}

% act here to specify a default column type

\SetTblrInner{
 width=\linewidth,
 columns={co=1},
 baseline=T,
 hspan=even,
 vspan=even,
 stretch=1.3,
 row{1}={font=\bfseries},
 hline{1,Z}={0.6mm},
 hline{2}={0.3mm}
}

\def\testTblrColspec#1{
  \hspace*{-2em}\texttt{\UseName{tl_if_empty:nTF}{#1}{<empty>}{#1}}
  \par\medskip
  \begin{tblr}{#1}
   Head1 & Head2 & Head3\\
   Row21 & Row22 & Row23 \\
   Row31 & Row32 & Row33 \\
   Row41Row41 & Row42 & Row43 \\
  \end{tblr}
  \par\medskip
}

\begin{document}

\testTblrColspec{}
\testTblrColspec{colspec={|l|X[r]|c|}}
\testTblrColspec{colspec={|Q[l,co=0]|X[r]|Q[c,co=0]|}}

\end{document}

enter image description here

3
  • 1
    In github.com/lvjr/tabularray/discussions/… I posted an experimental implementation for new option columns type=<single column type>, with which one can directly use columns type=X. Commented Jun 1, 2023 at 21:16
  • Thank you, but unfortunately this seems to force a standard and homogeneous column width even if I specify colspec in columns where I don't want the default value. I would expect a specific colspec to override the preamble columns={co=1}. The same happens with colspec={XXXXXXXXXXXX} in preamble (rdrg109's workaround)
    – Polizi8
    Commented Jun 2, 2023 at 17:15
  • 1
    @Polizi8 See update in my answer. Commented Jun 2, 2023 at 23:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .