2

This solution is exactly what I'm going for, but unfortunately the tabularray package removes the ability to use multicolumn and I cannot therefore get any of the solutions to work.

I tried just replacing the multicolumn command with Tabularray's \SetCell, but that was unsuccessful.

Would love some assist modifying the original solution or something different to achieve the same result (ideally still using tabularray as the base, but if I really can't, I can consider switching to other table packages for this table).

Here is an example table with the cell to strike through indicated.

\documentclass{article}
\usepackage{tabularray}

\begin{document}

\begin{tblr}{ colspec = {Q[l,m,2in]*{2}{Q[c,m]}}, hlines, vlines } Testing a cell & Test & More text\ Another row & & \ \SetRow{ht=1.5in}{Strike this cell out with an X\from bottom-left to top-right\and top-left to bottom-right\may have more than one row\or altered height} & & \ \end{tblr} \end{document}

F. Pantigny
  • 40,250
J M
  • 1,102
  • 1
    Seems like another task for [tag:nicematrix]. – Qrrbrbirlbel Oct 23 '23 at 18:17
  • @Qrrbrbirlbel I did consider it, but every other table is built with tabularray (working on a very large project), so I'm hoping I don't have to use a different table setup just for this one need. – J M Oct 23 '23 at 22:09

2 Answers2

5

This is a solution using nicematrix:

(1) Emulate the table using the nicematrix package.

The command \Block command creates a 9x1 multi-row/column cell. It doesn't create space, so empty rows were added. \\ is allowed inside \Block.

(2) The package creates Tikz nodes in the cells of the matrix.

The \CodeAfter command can be used to place some code that will be executed after construction of the matrix. With the tikz package loaded it is possible to draw the red lines between the corners of the Block.

d

\documentclass{article}
\usepackage{tabularray}

\usepackage{nicematrix} % added <<<<<<<<<<< \usepackage{tikz}% added <<<<<<<<<<<

\begin{document}

\begin{tblr}{
        colspec = {Q[l,m,2in]*{2}{Q[c,m]}},
        hlines,
        vlines
    }
    Testing a cell &amp; Test &amp; More text\\
    Another row &amp; &amp; \\
    \SetRow{ht=1.5in}{Strike this cell out with an X\\from bottom-left to top-right\\and top-left to bottom-right\\may have more than one row\\or altered height} &amp; &amp; \\
\end{tblr}

\bigskip

Using nicematrix:

\medskip

\begin{NiceTabular}{W{l}{2in}cc}[vlines,cell-space-top-limit=4pt, cell-space-bottom-limit=1pt] % vertical lines, expand the cells vertically
    \hline
    Testing a cell &amp; Test &amp; More text\\\hline
    Another row &amp; &amp; \\\hline
    \Block[l]{9-1}{Strike this cell out with an X\\from bottom-left to top-right\\and top-left to bottom-right\\may have more than one row\\or altered height} &amp; &amp; \\
    &amp;&amp;\\ % create space for the Block
    &amp;&amp;\\
    &amp;&amp;\\
    &amp;&amp;\\
    &amp;&amp;\\
    &amp;&amp;\\
    &amp;&amp;\\
    &amp;&amp;\\
    \hline
    \CodeAfter % draw a red X
    \tikz \draw [thick,red](3-|1) -- (last-|2)  ;
    \tikz \draw [thick,red](3-|2) -- (last-|1)  ;
\end{NiceTabular}   

\end{document}

Simon Dispa
  • 39,141
  • If I can’t resolve it using tabularray, I will have to go this route. – J M Oct 25 '23 at 00:46
  • Interesting workaround to ht = 1.5in, I tried myself (never used the package myself) and was hoping for something like \Block[height = 1.5in]{1-1}{…}. It's unfortunate that tblr produces a nice output out of the box where we need cell-space-limits here and then the first row is taller than the second because of the g in the first one. – Qrrbrbirlbel Oct 25 '23 at 09:10
  • @Qrrbrbirlbel Thank you for your comments. You are right, a height parameter is missing from this package. Or tabularray needs to allow execution of tikz commands – Simon Dispa Oct 25 '23 at 14:43
0

Following the comments of Qrrbrbirlbel to Simon Dispa's answer (+1), I add another answer with nicematrix.

In that solution, I have created a row of total height (\ht+\dp) equal to 1.5 in by adding a strut : \rule[-0.75in]{0pt}{1.5in}.

In have also drawn the red cross in the \CodeBefore in order to have a perfect output in the corners.

\documentclass{article}
\usepackage{tabularray}
\usepackage{nicematrix}
\usepackage{tikz}

\begin{document}

\begin{tblr}{ colspec = {Q[l,m,2in]*{2}{Q[c,m]}}, hlines, vlines } Testing a cell & Test & More text\ Another row & & \ \SetRow{ht=1.5in}{Strike this cell out with an X\from bottom-left to top-right\and top-left to bottom-right\may have more than one row\or altered height} & & \ \end{tblr}

\bigskip

Using \verb|nicematrix|:

\medskip

\begin{NiceTabular}{W{l}{2in}cc}[hvlines] \CodeBefore \begin{tikzpicture} \clip (3-|1) rectangle (last-|2) ; \draw [thick,red] (3-|1) -- (last-|2) (3-|2) -- (last-|1) ; \end{tikzpicture} \Body Testing a cell & Test & More text\ Another row \ \rule[-0.75in]{0pt}{1.5in} \Block[v-center]{}{Strike this cell out with an X\from bottom-left to top-right\and top-left to bottom-right\may have more than one row\or altered height} & & \ \end{NiceTabular}

\end{document}

Output of the above code

A zoom on a corner:

Zoom on a corner

For the first and the second rows, the spaces above and below the lines of text are exactly the sames as with {tabular} (by design of nicematrix).

It's possible to increase those spaces by using (for instance) \arraystretch.

F. Pantigny
  • 40,250