TikZ-Pic Tabularray – How to Wrap Column Content Inside Commands in Tabularray

tabularraytikz-pic

Tabularray: I want to create a column that prepends and appends some code to save space and avoid repetition, but I don't achieve that behavior.

At first, I tried (and failed) to create a new column type

\NewColumnType{t}[1]{Q[l,cmd=\adjustbox{valign=m}{\begin{tikzpicture} #1 \end{tikzpicture}}]}

After that I tried to use the preto & appto in that column and I achieved some advances but I wasn't able to insert \adjustbox{valign=m}{ because the brackets closure fails and also, I didn't see how to specify that behavior for column 1 but first row, I tried with cells and column{1}{2-Z} but I'm new at this and didn't make it

\documentclass{article}

\usepackage{tabularray}
\usepackage{tikz}
\usepackage{lipsum}
\usetikzlibrary{shapes.geometric, arrows.meta, calc, patterns, patterns.meta, shadows}
\usepackage{chemplants}

\begin{document}

    \begin{longtblr}[
        caption = {Materiales identificados},
        label = {table:materiales_identificados}
    ]{
        colspec = {c X},
        hlines,
        vlines,
        row{odd} = {bg=red!20!green!20!blue!20},
        row{1} = {
            bg = red!80!green!20!blue!20,
            font =  \large\bfseries
        },
        rowhead = 1,
        rows = {
            valign = m
        },
        column{1} = {
            preto = {\begin{tikzpicture}},
            appto = {\end{tikzpicture}}
        }
    }
    Simbología & descripción \\
%
        \pic [scale = 1] at (0, 0) {centrifugal pump};
        & \textbf{Bomba centrífuga}: \lipsum[1][1] 
    \end{longtblr}
\end{document}

How can I achieve this behavior for column 1 but first row USING tabularray ?

\adjustbox{valign=m}{
    \begin{tikzpicture}
        #1
    \end{tikzpicture}
}

Best Answer

cell{2-Z}{1} = {cmd=\adjusttikzpic} executes \adjusttikzpic for the content of the first column (except for the first cell), where \adjusttikzpic is defined in the following way:

\NewDocumentCommand{\adjusttikzpic}{m}{%
  \adjustbox{valign=m}{%
    \begin{tikzpicture} 
      #1 
    \end{tikzpicture}%
  }
}

The full code:

\documentclass{article}

\usepackage{tabularray}
\usepackage{tikz}
\usepackage{lipsum}
\usetikzlibrary{shapes.geometric, arrows.meta, calc, patterns, patterns.meta, shadows}
\usepackage{chemplants}

\usepackage{adjustbox} % for \adjustbox

\NewDocumentCommand{\adjusttikzpic}{m}{% define \adjusttikzpic command
  \adjustbox{valign=m}{%
    \begin{tikzpicture} 
      #1 
    \end{tikzpicture}%
  }
}

\begin{document}

    \begin{longtblr}[
        caption = {Materiales identificados},
        label = {table:materiales_identificados}
    ]{
        colspec = {c X},
        hlines,
        vlines,
        row{odd} = {bg=red!20!green!20!blue!20},
        row{1} = {
            bg = red!80!green!20!blue!20,
            font =  \large\bfseries
        },
        rowhead = 1,
        rows = {
            valign = m
        },
        cell{2-Z}{1} = {cmd=\adjusttikzpic}, % executing \adjusttikzpic for the content of the first column (except for the first cell)
    }
    Simbología & Descripción \\
%
        \pic [scale = 1] at (0, 0) {centrifugal pump};
        & \textbf{Bomba centrífuga}: \lipsum[1][1] 
    \end{longtblr}
\end{document}

enter image description here