3

I am working to create a table with alternating rows—the first has 5 columns and the second is a merged column that just consists of text.

However, I can't for the life of me, get it to wrap the text. I have tried hspan=minimal, Q columns, and X columns (albeit perhaps incorrectly?)

Thanks in advance!

\begin{tblr}{
    colspec={@{}c|Q[l]|c|c|c|@{}},
    width=\linewidth
}
Thing 1 & Thing 2 & Thing 3 & Thing 4  & Thing 5\\
\SetCell[c=5]{c} I am a dummy string tall and skinny! Here is where I start start start! This is where I sing! There is my middle! And last we have my end end end!& & & & \\
\end{tblr}

2 Answers 2

0

You can specify the total width of the merged cell:

\documentclass{article}

\usepackage{tabularray}

\begin{document}

\begin{tblr}{
    colspec={@{}X[c]|X[l]|X[c]|X[c]|X[c]|@{}},
    width=\linewidth
}
Thing 1 & Thing 2 & Thing 3 & Thing 4  & Thing 5\\
\SetCell[c=5]{\linewidth,halign=l} I am a dummy string tall and skinny! Here is where I start start start! This is where I sing! There is my middle! And last we have my end end end!& & & & \\
\end{tblr}

\end{document}

enter image description here

(I replaced your c columns with X[c] so the table has a change to fill the width you specified equally and not enlarging just the last column.)

4
  • I am going to name my first child samcarter! For bonus points, can you tell me if there is a way to have it right-align with the text on the right using this colspec instead (I had made a mistake)—it's quite similar. colspec={@{}Q[l]|Q[l]|Q[c]|Q[c]|Q[r]|@{}},
    – jesse
    Aug 17, 2022 at 2:00
  • @Jesse Are you maybe looking for halign=r or halign=j? If not, can you please make a sketch how the result should look like? Aug 17, 2022 at 10:33
  • Thank you so much! I was ignorant of halign=j—thank you so much! Hey, where is the best/most complete documentation on this?
    – jesse
    Aug 17, 2022 at 20:38
  • @Jesse You're welcome! Aug 17, 2022 at 20:39
3

You can use the selector cell{row(s)}{column(s)} to define a multispan cell. Then you should use hspan = minimal

As described on tabularray docs in 3.1.4 Hspan and Vspan Algorithms:

\documentclass[12pt]{article}
\usepackage{tabularray}

% Random text
% Don't use this on your document
\usepackage{lipsum}

\begin{document}
        
    \begin{tblr}{
        colspec = {*{5}X},
        hlines,
        vlines,
        % minimal span
        hspan=minimal,
        width = 1\columnwidth,
        rows = {
            valign = m,
            halign = c
        },
        % cell in row 5 column 1 will have a
        % colspan of 5 (c=5), for rowspan use r=#
        cell{5}{1} = {c=5}{},
        % alignment for row 5
        row{5} = {
            halign = j
        },
    }
        1 & {835\\ 586} & 158 & 878 & 274 \\
        2 & 285 & 608 & 904 & 285 \\
        3 & 107 & 230 & 358 & 368 \\
        4 & 415 & 301 & 182 & 147 \\
        \lipsum[1] &&&&
    \end{tblr}
% Termina nuestro documento
\end{document}

enter image description here

4
  • I really like this answer, but how can I make it fit the entire \linewidth (this just sizes it to the headers, right)?
    – jesse
    Aug 17, 2022 at 22:25
  • @Jesse As you see, when specifying X columns you must define the key width, on this key you must specify what you want. I used in this example \columnwidth, you can use \textwidth or something similar Aug 18, 2022 at 1:08
  • If that's not what you asked for, could you explain it in more detail please? I'm not a native speaker so maybe I'm missing something XD Aug 18, 2022 at 1:12
  • In your case you need to define table width only when you like that table width is narrower (or wider, but this is not recommended) than width of environment (in your case the width of text area, i. e. \textwidth}. Of course, complete table has the same width, but when you use talltblr, the caption width can not be wider than table. +1 for nice answer!
    – Zarko
    Aug 28, 2022 at 8:30

You must log in to answer this question.

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